当前位置:   article > 正文

c# wpf LiveCharts MVVM绑定 简单试验

c# wpf LiveCharts MVVM绑定 简单试验

1.概要

c# wpf LiveCharts MVVM绑定 简单试验

2.代码

  1. <Window x:Class="WpfApp3.Window3"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
  7. xmlns:local="clr-namespace:WpfApp3"
  8. mc:Ignorable="d"
  9. Title="Window3" Height="450" Width="800">
  10. <Grid>
  11. <lvc:CartesianChart Margin="10" LegendLocation="Bottom">
  12. <lvc:CartesianChart.Series>
  13. <lvc:LineSeries Fill="#DBF3F9" Stroke="#5CD0E1" Title="消费"
  14. Values="{Binding SeriesValues}" PointGeometrySize="0" DataLabels="True"/>
  15. </lvc:CartesianChart.Series>
  16. <lvc:CartesianChart.AxisX>
  17. <lvc:Axis Labels="{Binding SeriesLabels}" Margin="10">
  18. <lvc:Axis.Separator>
  19. <lvc:Separator StrokeThickness="0.5" Step="1" />
  20. </lvc:Axis.Separator>
  21. </lvc:Axis>
  22. </lvc:CartesianChart.AxisX>
  23. <lvc:CartesianChart.AxisY>
  24. <lvc:Axis MinValue="0" ShowLabels="True"/>
  25. </lvc:CartesianChart.AxisY>
  26. </lvc:CartesianChart>
  27. </Grid>
  28. </Window>

 

  1. using LiveCharts;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using LiveCharts.Wpf;
  16. namespace WpfApp3
  17. {
  18. /// <summary>
  19. /// Window3.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class Window3 : Window
  22. {
  23. public Window3()
  24. {
  25. InitializeComponent();
  26. this.DataContext = new HomePgVM2();
  27. }
  28. }
  29. public class HomePgVM2 : NotifyPropertyBase
  30. {
  31. public ChartValues<double> SeriesValues { get; set; }
  32. public string[] SeriesLabels { get; set; }
  33. public HomePgVM2()
  34. {
  35. SeriesValues = new ChartValues<double>();
  36. double[] dValues = new double[] { 581, 423, 634, 658, 134, 256, 318 };
  37. SeriesLabels = new[] { "8-1", "8-2", "8-3", "8-4", "8-5", "8-6", "8-7" };
  38. for (int i = 0; i < dValues.Length; i++)
  39. {
  40. SeriesValues.Add(dValues[i]);
  41. }
  42. }
  43. }
  44. }

3.运行结果

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号