WPF ListChart 折线图控件教程 - 简单易用图表绘制
WPF (Windows Presentation Foundation) 是微软开发的用户界面框架,用于开发桌面应用程序。ListChart 是 WPF 中的一个控件,用于显示折线图。
使用 ListChart 控件可以很方便地绘制折线图。首先,在 XAML 文件中添加 ListChart 控件:
<Window x:Class='WpfApp1.MainWindow'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Title='MainWindow' Height='450' Width='800'>
<Grid>
<ListChart x:Name='chart'/>
</Grid>
</Window>
然后,在代码中设置 ListChart 的数据源和样式:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// 设置 ListChart 的数据源
chart.ItemsSource = new List<int> { 1, 3, 2, 4, 5, 3, 6 };
// 设置 ListChart 的样式
chart.LineColor = Brushes.Blue;
chart.LineThickness = 2;
chart.PointColor = Brushes.Red;
chart.PointSize = 6;
}
}
这样就可以在窗口中显示一个简单的折线图了。如果需要显示更复杂的折线图,可以使用 ListChart 的其他属性和方法,例如设置坐标轴、添加多条线段等。
原文地址: http://www.cveoy.top/t/topic/oK34 著作权归作者所有。请勿转载和采集!