dev express 15.2
绘制曲线
- 前端代码
<dxc:ChartControl Grid.Row="1"><dxc:XYDiagram2D EnableAxisXNavigation="True"><dxc:LineSeries2D x:Name="series" CrosshairLabelPattern="{}{A} : {V:F2}"/></dxc:XYDiagram2D>
</dxc:ChartControl>
- 后端代码
Dispatcher.BeginInvoke(new Action(() =>
{Random random = new Random();series.Points.BeginInit();series.Points.Clear();for (int i = 0; i < 100000; i++)series.Points.Add(new SeriesPoint((double)i, random.NextDouble()));series.Points.EndInit();
}), DispatcherPriority.Background);
执行的结果图标很卡,一样的代码和dev express的demo性能差距很大
窗口不要最大化,窗口太大显示效率明显降低,devexpress demo最大化之后也存在这个问题。
ScottPlot
dotnet中绘图可以使用scottplot,基于opengl比livechart的基于skia效率高很多
nuget安装scottplot.wpf
- 前端代码
xmlns:sp="clr-namespace:ScottPlot;assembly=ScottPlot.WPF"
...
<sp:WpfPlot Grid.Row="1" Name="series"></sp:WpfPlot>
- 后端代码
Random random = new Random();
double[] pointCollection = new double[1000000];
Parallel.For(0, 1, (i) =>
{for (int j = 0; j < pointCollection.Length; j++)pointCollection[j] = random.NextDouble();
});
series.Plot.AddSignal(pointCollection);
Crosshair = series.Plot.AddCrosshair(0, 0);
series.Plot.SetAxisLimitsY(0, 1);
series.Plot.XAxis.SetBoundary(0, pointCollection.Length);
series.Plot.YAxis.LockLimits(true);
series.Refresh();
//MouseMove Event-----------------------------------------------------
(double coordinateX, double coordinateY) = series.GetMouseCoordinates();
Crosshair.X = coordinateX;
Crosshair.Y = coordinateY;
series.Refresh();
scichart
https://www.scichart.com/example/wpf-chart/wpf-line-chart-example/
有免费的版本可以在网上下载