WPF中LiveCharts报表控件的应用示例

  • Post author:
  • Post category:其他


在这里插入图片描述

如上图所示,首先我们在ViewModel中定义好相应的数组属性,并初始化Series

public class LiveChartsViewModel :ViewModelBase
    {
        public LiveChartsViewModel()
        {
            SeriesCollection = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title="2015",
                    Values = new ChartValues<double> { 3, 5, 7, 4 },
                    LabelPoint = point => point.Y + "K",                                    
                    DataLabels = true,

                },
                 new ColumnSeries
                {
                     Title="2016",
                    Values = new ChartValues<decimal> { 5, 6, 2, 7 },
                     LabelPoint = point => point.Y + "K",               
                     DataLabels = true,


                },
                 new ColumnSeries
                 {
                     Title="2017",
                     Values=new ChartValues<decimal>{1,2,3,4},
                     LabelPoint = point => point.Y + "K",                
                     DataLabels = true,


                 }
            };

            Labels = new[] { "中国", "美国", "澳大利亚", "日志" };

        }

        public SeriesCollection SeriesCollection { get; set; }

        public string[] Labels { get; set; }

    }
}

第二步,在XAML前端代码中,我们写上相应的代码并进行绑定

<Grid>
    <lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Right">
        <lvc:CartesianChart.AxisX>
            <lvc:Axis Title="连续3年进出口贸易变化" Labels="{Binding Labels}"></lvc:Axis>
        </lvc:CartesianChart.AxisX>
    </lvc:CartesianChart>
</Grid>



版权声明:本文为qq_37189288原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。