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

            };
        }
    }
相关推荐
dalong106 小时前
WPF:箭头绘制程序
wpf·自定义绘制
张工在路上1 天前
WPF 布局基础概述
大数据·hadoop·wpf
迪飞特科技2 天前
分布式事务下 Spring 声明式事务失效的 3 种修复方案
分布式·spring·wpf
2601_962174175 天前
Redis 简介
数据库·redis·wpf
SamChan906 天前
Python+PyMuPDF提取PDF表格并翻译:表格结构检测与双语重建实战
windows·python·ai·pdf·wpf
SamChan906 天前
Python+OpenCV检测PDF翻译后排版偏移:像素级格式一致性验证
python·opencv·ai·pdf·wpf
FuckPatience6 天前
WPF 拿到控件的最初样式,修改获得焦点样式
wpf
主宰者6 天前
【WPF】MainWindow前添加加载窗口,发现加载过程中有白色无内容窗口闪烁一下的解决方案
wpf
Vae_Mars7 天前
WPF中的ControlTemplate(控件模板)
wpf
SamChan907 天前
Python+ReportLab自动生成PDF翻译质量审计报告:从数据到可视化的完整方案
开发语言·python·ai·pdf·wpf