1.首先nuget上下载两个包:wpftoolkit和Controls.DataVisualization.Toolkit(工具-nuget包管理器-管理解决方案的nuget程序包,输入两个包名并安装)
2.在xmal文件中导入这两个包,代码如下:
xmlns:dc = "clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:dv = "clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
3.在xaml中具体使用代码示例:(红色部分为设置数据点大小的代码)
<dc:Chart Canvas.Top = "80" Canvas.Left = "10" Name = "mcChart"
DockPanel.Dock="Left"
Background = "LightBlue" BorderThickness="1,1,1,0.01" >
<dc:Chart.Series>
<dc:LineSeries Title = "Line"
IndependentValueBinding = "{Binding Path=Key}"
DependentValueBinding = "{Binding Path=Value}">
<dc:DataPointSeries.DataPointStyle>
<Style
BasedOn="{StaticResource {x:Type dc:LineDataPoint}}"
TargetType="{x:Type dc:LineDataPoint}">
<Setter Property="Width" Value="2" />
<Setter Property="Height" Value="2" />
</Style>
</dc:DataPointSeries.DataPointStyle>
</dc:LineSeries>
</dc:Chart.Series>
</dc:Chart>
4.xaml.cs文件中代码示例
KeyValuePair<int, int>[] values = new KeyValuePair<int, int>[]{
new KeyValuePair < int , int > ( 1 , 100 ),
new KeyValuePair < int , int > ( 2 , 130 ),
new KeyValuePair < int , int > ( 3 , 150 ),
new KeyValuePair < int , int > ( 4 , 125 )
};
写的不对的地方希望大家指正,谢谢~