wpf 图表制作 LiveCharts

CartesianChart 笛卡尔图表 》》直接前端绘制曲线数据

csharp 复制代码
<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1" xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <wpf:CartesianChart AnimationsSpeed="0:0:0:2" LegendLocation="Bottom" >
            <wpf:CartesianChart.Series  >
                <wpf:LineSeries DataLabels="True"  Fill="Azure" Stroke="Green" Values="10,4,40,8,18"  Title="AAAAA">
                </wpf:LineSeries>
                <wpf:LineSeries Values="22,7,20,4,38" Title="BBBB" ></wpf:LineSeries>
            </wpf:CartesianChart.Series>
            <wpf:CartesianChart.AxisX  >
                <wpf:Axis Title="xxxxx" ShowLabels="True" Labels="{Binding Tit}">
                   <wpf:Axis.Separator>
                     <wpf:Separator StrokeThickness="0.5" Step="1" />
                  </wpf:Axis.Separator>
                </wpf:Axis>
            </wpf:CartesianChart.AxisX>
        </wpf:CartesianChart>
        
    </Grid>
</Window>
# Stroke  是描边的颜色
》》》后端事件添加数据
   <wpf:CartesianChart Name="chart"/>
   
    SeriesCollection series = new SeriesCollection()
    {
        new LineSeries
        {
            Values = new ChartValues<double> { 3, 5, 7, 4 },
            Fill=new SolidColorBrush(Colors.IndianRed),
        },

    };
    chart.Series = series;
>>>MVVM绑定
 <wpf:CartesianChart Name="chart"/>
   //MainWindow中进行绑定
  this.DataContext = new MainViewModel();
  
  //MainWindow的ViewModel类
   public class MainViewModel : INotifyPropertyChanged
    {
       
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string name = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }

        private SeriesCollection _series;
        public SeriesCollection Series
        {
            get
            {
                return _series;
            }
            set
            {
                _series = value;
                OnPropertyChanged();
            }
        }


        public MainViewModel()
        {
            Series = new SeriesCollection()
            {
                new LineSeries
                {
                    Values = new ChartValues<double> { 3, 5, 7, 4,100,50,2 },
                    Fill=new SolidColorBrush(Colors.LightGreen),
                },

            };
        }
    }
相关推荐
samble3 天前
从零搭建灌装监控系统(四):深色主题与样式系统,ResourceDictionary 统一管理
c#·wpf·mvvm·样式·工业控制
_Jonas3 天前
.net framework开发环境正式环境配置文件的切换
.net·wpf
dalong105 天前
WPF:Modbus 状态监控
wpf·modbus
He BianGu5 天前
【WPF-VisionMaster】机器视觉通用平台V5.0版本发行说明
opencv·c#·wpf·halcon·机器视觉·visionmaster
fogota8 天前
Emoji与Segoe MDL2 Assets的比较
c#·wpf
fogota9 天前
C# WPF 按钮加载字体图标 / 动物头像
c#·.net·wpf
fogota9 天前
C# WPF 按钮加载系统图标 / 动物头像
c#·.net·wpf
军训猫猫头9 天前
C# 封装 MySQL 自动写入与查询工具类(基于 MySqlConnector)
mysql·c#·.net·wpf
gis开发之家10 天前
Spring Boot 4 定时任务与异步线程池:从 @Scheduled 到高并发任务编排(生产级实战)
java·spring boot·后端·wpf·spring boot4
clz131452111 天前
如何设计一个优雅可靠的金融级联机接口
wpf