• WPF LiveChart示例


    前端页面代码

    <TabItem Header="直方图" >
                    <wpf:CartesianChart Series="{Binding SeriesCollectionAnayColumn}" 
                                        LegendLocation="Right" >
                        <wpf:CartesianChart.AxisX>
                            <wpf:Axis Title="区间" Labels="{Binding LabelsColumn}"  Foreground="#FF8DEBF7"/>
                        </wpf:CartesianChart.AxisX>
                        <wpf:CartesianChart.AxisY>
                            <wpf:Axis Title="频率"  LabelFormatter="{Binding YFormatterColumn}" Foreground="#FF8DEBF7"/>
                        </wpf:CartesianChart.AxisY>
                        <wpf:CartesianChart.DataTooltip>
                            <!--The Selection mode property should be done automatically in future versions-->
                            <wpf:DefaultTooltip SelectionMode="SharedXValues" Background="DarkSlateGray"/>
                        </wpf:CartesianChart.DataTooltip>
                    </wpf:CartesianChart>
    
    
    
                </TabItem>
                <TabItem Header="波形图">
                    <wpf:CartesianChart Series="{Binding SeriesCollectionAnayLine}" 
                                        LegendLocation="Right" >
                        <wpf:CartesianChart.AxisX>
                            <wpf:Axis Title="时间" Labels="{Binding LabelsLine}"  Foreground="#FF8DEBF7"/>
                        </wpf:CartesianChart.AxisX>
                        <wpf:CartesianChart.AxisY>
                            <wpf:Axis Title=""  LabelFormatter="{Binding YFormatterLine}" Foreground="#FF8DEBF7"/>
                        </wpf:CartesianChart.AxisY>
                        <wpf:CartesianChart.DataTooltip>
                            <!--The Selection mode property should be done automatically in future versions-->
                            <wpf:DefaultTooltip SelectionMode="SharedXValues" Background="DarkSlateGray"/>
                        </wpf:CartesianChart.DataTooltip>
                    </wpf:CartesianChart>
                </TabItem>

    ViewModel代码

    //定义页面上绑定的数据源
     public SeriesCollection _seriesCollectionAnayColumn { get; set; }
            public SeriesCollection SeriesCollectionAnayColumn
            {
                get => _seriesCollectionAnayColumn;
                set
                {
                    _seriesCollectionAnayColumn = value;
                    RaisePropertyChanged();
                }
            }
            public string[] _labelsColumn { get; set; }
            public string[] LabelsColumn
            {
                get => _labelsColumn;
                set
                {
                    _labelsColumn = value;
                    RaisePropertyChanged();
                }
            }
            public Func<double, string> _yFormatterColumn { get; set; }
            public Func<double, string> YFormatterColumn
            {
                get => _yFormatterColumn;
                set
                {
                    _yFormatterColumn = value;
                    RaisePropertyChanged();
                }
            }
    
    
            public SeriesCollection _seriesCollectionAnayLine { get; set; }
            public SeriesCollection SeriesCollectionAnayLine
            {
                get => _seriesCollectionAnayLine;
                set
                {
                    _seriesCollectionAnayLine = value;
                    RaisePropertyChanged();
                }
            }
            public string[] _labelsLine { get; set; }
            public string[] LabelsLine
            {
                get => _labelsLine;
                set
                {
                    _labelsLine = value;
                    RaisePropertyChanged();
                }
            }
            public Func<double, string> _yFormatterLine { get; set; }
            public Func<double, string> YFormatterLine
            {
                get => _yFormatterLine;
                set
                {
                    _yFormatterLine = value;
                    RaisePropertyChanged();
                }
            }
    
    
    
    //为页面绑定的数据源赋值
       //折线图
                            SeriesCollectionAnayLine = new SeriesCollection();
                            LabelsLine =data.TrainTime;
                        YFormatterLine = value => value.ToString("f4");
     SeriesCollectionAnayLine.Add(new LineSeries
                            {
                                Title = data.TestData[0].DataType,
                                Values = new ChartValues<float>(YAxis),
                                LineSmoothness = 0
                            });
    
    
     //直方图
                                SeriesCollectionAnayColumn = new SeriesCollection();
                                LabelsColumn = columuResult.XAxis;
                                YFormatterColumn = value => value.ToString("f3");
                                SeriesCollectionAnayColumn.Add(new ColumnSeries
                                {
                                    Title = "频率",
                                    Values = new ChartValues<float>(columuResult.YAxis)
                                });
  • 相关阅读:
    windows 环境下在anaconda 3中安装python2和python3两个环境(python2和python3共存)
    python 中,如何在一个函数中调用另一个函数返回的多个值中的一个?
    Coursera 机器学习 第一周 学习笔记
    正则表达式 注释
    正则表达式 分组
    24_04SpringMVC实现文件上传及拦截器
    前端之CSS基础
    前端之html
    MySQL数据库实战之优酷
    数据库基础加练习
  • 原文地址:https://www.cnblogs.com/ljy0905/p/9935966.html
Copyright © 2020-2023  润新知