zoukankan      html  css  js  c++  java
  • 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)
                                });
  • 相关阅读:
    多线程--ThreadLocal类
    常用开发类库支持--UUID及空值处理Optional
    国际化的程序实现及其原理
    浅析java设计模式(一)----异构容器,可以存储任何对象类型为其他类提供该对象
    使用批处理命令注册运行mysql数据库,无需注册mysql服务,可以在任意电脑登录使用
    计算机中位、字长、字的区别
    SQL Server用户自定义数据类型
    简单的回合制小游戏
    单链表创建、删除、查找、插入之C语言实现
    LeetCode-905 Sort Array By Parity Solution (with Java)
  • 原文地址:https://www.cnblogs.com/ljy0905/p/9935966.html
Copyright © 2011-2022 走看看