- NuGet安装LiveCharts和LiveCharts.Wpf
- xaml的demo
<Window x:Class="liveChartsApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:liveChartsApp" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="LiveCharts Demo" Height="450" Width="800">
<Grid>
<lvc:CartesianChart x:Name="lineChart" Margin="10">
<lvc:CartesianChart.Series>
<lvc:LineSeries Title="Series 1" Values="{Binding LineChartValues}" PointGeometry="{x:Null}"/>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="X Axis Title" Labels="{Binding Labels}"/>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Y Axis Title"/>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</Window>
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
namespace liveChartsApp
{
public partial class MainWindow : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ChartValues<ObservablePoint> _lineChartValues;
public ChartValues<ObservablePoint> LineChartValues
{
get { return _lineChartValues; }
set
{
_lineChartValues = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LineChartValues)));
}
}
private List<string> _labels;
public List<string> Labels
{
get { return _labels; }
set
{
_labels = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Labels)));
}
}
public MainWindow()
{
InitializeComponent();
LineChartValues = new ChartValues<ObservablePoint>
{
new ObservablePoint(1,5),
new ObservablePoint(2, 7),
new ObservablePoint(3, 3),
new ObservablePoint(4, 10),
new ObservablePoint(5, 8)
};
Labels = new List<string> { "JAN", "FEB", "MAR", "APR", "MAY" };
DataContext = this;
}
}
}
- INotifyPropertyChanged的作用是用来通报更新数据的,这次是初次尝试,用来记录;
这是效果图![在这里插入图片描述](https://img-blog.csdnimg.cn/08acf937a8674580a148c6ac78e97272.jpeg#pic_center)