好用的WinForm圖表庫ScottPlot


 

先上成品圖,看起來還不錯對吧。

WinForm下引入包

ScottPlot.WinForms

據說WPF也可以用,目前沒有測試過,也不是本文講解。WPF中引入的包叫這個,有興趣的可以了解下

1.通過Nuget安裝 ScottPlot.WPF
2.添加一個 WpfPlot 組件到布局中, 並設置Name

   <WpfPlot Name="WpfPlot1" />

 

 

WinForm下安裝好就有這個了

 

 

 拖出來

 

 

 

我拖了4個,然后放了個timer

 

 

那圖是怎么生成呢,特別簡單,先上個示例

double[] dataX = new double[] {1, 2, 3, 4, 5};
double[] dataY = new double[] {1, 4, 9, 16, 25};
formsPlot1.Plot.AddScatter(dataX, dataY);
formsPlot1.Refresh();

 

這樣就OK了,

重置圖表怎么搞?

Reset就可以。

formsPlot1.Reset();

 

一定記得最后要Refresh一下才可以。

 

剩下的其他樣式呢?

我提供我上面有的這4個吧

        int pointCount = 20;
            double[] xs1 = ScottPlot.DataGen.RandomWalk(r, pointCount);
            double[] ys1 = ScottPlot.DataGen.RandomWalk(r, pointCount);
            double[] xs2 = ScottPlot.DataGen.RandomWalk(r, pointCount);
            double[] ys2 = ScottPlot.DataGen.RandomWalk(r, pointCount);

            // plot the data
            formsPlot1.Reset();
            formsPlot1.plt.PlotScatter(xs1, ys1);
            formsPlot1.plt.PlotScatter(xs2, ys2);

            // additional styling
            formsPlot1.plt.Title($"Scatter Plot ({pointCount} points per group)");
            formsPlot1.plt.XLabel("Horizontal Axis Label");
            formsPlot1.plt.YLabel("Vertical Axis Label");
            formsPlot1.Render();



            pointCount = 10_000;
            ys1 = ScottPlot.DataGen.RandomWalk(r, pointCount);
            ys2 = ScottPlot.DataGen.RandomWalk(r, pointCount);

            // plot the data
            formsPlot2.Reset();
            formsPlot2.plt.PlotSignal(ys1);
            formsPlot2.plt.PlotSignal(ys2);

            // additional styling
            formsPlot2.plt.Title($"Line Plot ({10_000:N0} points each)");
            formsPlot2.plt.XLabel("Horizontal Axis Label");
            formsPlot2.plt.YLabel("Vertical Axis Label");
            formsPlot2.Render();



            pointCount = 5;
            double[] xs = ScottPlot.DataGen.Consecutive(pointCount);
            double[] ys = ScottPlot.DataGen.RandomWalk(r, pointCount, mult: 50, offset: 100);

            // plot the data
            formsPlot3.Reset();
            formsPlot3.plt.PlotBar(xs, ys);

            // additional styling
            formsPlot3.plt.Title("Simple Bar Graph");
            formsPlot3.plt.XLabel("Horizontal Axis Label");
            formsPlot3.plt.YLabel("Vertical Axis Label");
            //formsPlot3.plt.Axis(y1: 0);
            formsPlot3.Render();



            pointCount = 5;
            ys1 = ScottPlot.DataGen.RandomWalk(r, pointCount, mult: 50, offset: 100);
            ys2 = ScottPlot.DataGen.RandomWalk(r, pointCount, mult: 50, offset: 100);

            // collect the data into groups
            string[] groupLabels = { "One", "Two", "Three", "Four", "Five" };
            string[] seriesLabels = { "Group A", "Group B" };
            double[][] barHeights = { ys1, ys2 };

            // plot the data
            formsPlot4.Reset();
            formsPlot4.plt.PlotBarGroups(groupLabels, seriesLabels, barHeights);

            // additi4nal styling
            formsPlot4.plt.Title("Bar Graph");
            formsPlot4.plt.XLabel("Horizontal Axis Label");
            formsPlot4.plt.YLabel("Vertical Axis Label");
            //formsPlot4.plt.Legend(location: ScottPlot.legendLocation.upperLeft);
            //formsPlot4.plt.Axis(y1: 0);
            formsPlot4.Render();

 

 

就這樣吧~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM