一、使用ScottPlot.Wpf
官网地址:https://scottplot.net/quickstart/wpf/
1、添加NuGet包:ScottPlot.Wpf
2、XAML映射命名空间:
xmlns:ScottPlot="clr-namespace:ScottPlot.WPF;assembly=ScottPlot.WPF"
3、简单示例:
<ScottPlot:WpfPlot x:Name="WpfPlot" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
private void UpdateTableData()
{
try
{
WpfPlot.Plot.Clear();
WpfPlot.Plot.XLabel("Distance(mm)");
WpfPlot.Plot.YLabel("Height(mm)");
List<double> PosData = new List<double>() { 1, 2, 3, 4, 5, 6, 7, 8 };
List<double> HeightData_1 = new List<double>() { 1, 4, 9, 5, 16, 22, 7, 25 };
double[] PData = PosData.ToArray();
double[] CH_1 = HeightData_1.ToArray();
if (PData.Length <= 0) return;
var spio = WpfPlot.Plot.Add.ScatterLine(PData, CH_1, ScottPlot.Color.FromColor(System.Drawing.Color.DarkRed));
spio.LegendText = "HeightData01";
spio.Smooth = true;// 指定曲线为平滑曲线
设置图例
var legend = WpfPlot.Plot.Legend;
legend.Alignment = Alignment.LowerRight;//设置位置为右下
legend.FontSize = 13; // 图例字体大小
WpfPlot.Plot.Axes.AutoScale(false, false);
WpfPlot.Plot.Title("Data Table", 20);
WpfPlot.Refresh();
}
catch (Exception ex)
{
}
}