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),
                },

            };
        }
    }
相关推荐
samble12 小时前
从零搭建半导体设备上位机(四):单实例、启动流程与配置文件,App 里那 526 行到底在干什么
wpf·配置文件·单实例
浪扼飞舟20 小时前
WPF(控件的继承树、内容控件、布局控件)
wpf
avi91114 天前
电影开源Jevdo - 源码介绍(vue版)没有android 和 没有wpf
android·wpf·框架·数据爬虫·meego·电影管理
吾与谁归in5 天前
C#脚本工具,支持智能提示自动补全(WPF + Roslyn + AvalonEdit)
开发语言·c#·wpf
昂好的day5 天前
WPF 从零入门(上):WPF 是什么、XAML 语法、布局与样式全解
开发语言·c#·wpf
影寂ldy6 天前
WPF导航窗体+Page页面跳转 知识点整理
wpf
He BianGu6 天前
【WPF-Control教程】IOC 依赖注入
c#·wpf·wpf-control
He BianGu6 天前
【WPF-Control教程】H.Extensions.Behvaiors 开发文档
c#·wpf·wpf-control
He BianGu6 天前
【WPF-Control教程】H.Style 开发文档
c#·wpf·wpf-control
麻瓜code6 天前
分布式锁演进:从一个用户下两单,到 Redisson,我改了四版
分布式·wpf