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

            };
        }
    }
相关推荐
光泽雨2 天前
控件Password附加属性
wpf
samble6 天前
从零搭建半导体设备上位机(十二):参数设置页,表单校验、范围校验与配方联动
wpf·数据校验·validationrule
samble15 天前
从零搭建半导体设备上位机(九):拖拽与交互,Adorner、DragDrop 与晶圆拖放信息
wpf·拖拽·adorner
郝学胜-神的一滴16 天前
AI 编程智能体 27:吃透MCP通信机制
人工智能·python·langchain·wpf·numpy·scikit-learn
波力海苔夹心脆67517 天前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
陈仓主教17 天前
# WPF CheckBox 控件详解与使用—WPF 中的控件(6)--复选框控件(CheckBox)
wpf
光泽雨19 天前
WPF 音视频四大核心方案对比
wpf·音视频
浪扼飞舟20 天前
WPF(数据绑定)
wpf
samble21 天前
从零搭建半导体设备上位机(四):单实例、启动流程与配置文件,App 里那 526 行到底在干什么
wpf·配置文件·单实例
浪扼飞舟21 天前
WPF(控件的继承树、内容控件、布局控件)
wpf