当前位置:   article > 正文

c# wpf LiveCharts 绑定 简单试验

c# wpf LiveCharts 绑定 简单试验

1.概要

c# wpf LiveCharts 绑定 简单试验

2.代码

  1. <Window x:Class="WpfApp3.Window2"
  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="Window2" Height="450" Width="800">
  10. <Grid>
  11. <lvc:CartesianChart Series="{Binding Series}" LegendLocation="Bottom"/>
  12. </Grid>
  13. </Window>
  1. using LiveCharts.Wpf.Charts.Base;
  2. using LiveCharts.Wpf;
  3. using LiveCharts;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. using System.ComponentModel;
  18. using System.Runtime.CompilerServices;
  19. namespace WpfApp3
  20. {
  21. /// <summary>
  22. /// Window2.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class Window2 : Window
  25. {
  26. public Window2()
  27. {
  28. InitializeComponent();
  29. this.DataContext = new HomePgVM();
  30. }
  31. }
  32. public class HomePgVM : NotifyPropertyBase
  33. {
  34. public SeriesCollection Series { get; set; }
  35. public HomePgVM()
  36. {
  37. Series = new SeriesCollection()
  38. {
  39. new LineSeries
  40. {
  41. Title="充值",
  42. DataLabels=true,
  43. Values = new ChartValues<double> { 23, 15, 47, 64,30,32,21 },
  44. //Fill=new SolidColorBrush(Colors.LightGreen),
  45. },
  46. };
  47. }
  48. }
  49. /// <summary>
  50. /// 绑定UI显示--创建通知基类
  51. /// 继承 INotifyPropertyChanged(作用:当属性发生变化时,传递变化属性的值)
  52. /// </summary>
  53. public class NotifyPropertyBase : INotifyPropertyChanged
  54. {
  55. public event PropertyChangedEventHandler PropertyChanged;
  56. public void Notify([CallerMemberName] string propName = "")
  57. {
  58. if (PropertyChanged != null)
  59. PropertyChanged(this, new PropertyChangedEventArgs(propName));
  60. }
  61. protected void SetProperty<T>(ref T prop, T value, [CallerMemberName] string propertyName = null)
  62. {
  63. if (EqualityComparer<T>.Default.Equals(prop, value) == false)
  64. {
  65. prop = value;
  66. Notify(propertyName);
  67. }
  68. }
  69. }
  70. }

 

3.运行结果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/382479
推荐阅读
相关标签
  

闽ICP备14008679号