示例一:
创建和绑定livechart。
xaml:
<Window x:Class="chart_line.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:chart_line"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<lvc:CartesianChart Series="{Binding SeriesCollection}" />
</Grid>
</Window>
xaml.cs:
using LiveCharts;
using LiveCharts.Wpf;
namespace chart_line
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public SeriesCollection SeriesCollection { get; set; }
public MainWindow()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<double> { 3, 5, 7, 4 }
},
new ColumnSeries
{
Values = new ChartValues<decimal> { 5, 6, 2, 7 }
}
};
DataContext = this;
}
}
}