一.net下的圖表控制元件NPlot的基本用法
NPlot的基本用法
圖表控制元件一直是很難找的,特別是免費又強大的。NPlot是一款非常難得的.Net平臺下的圖表控制元件,能做各
種曲線圖,柱狀圖,餅圖,散點圖,股票圖等,而且它免費又開源,使用起來也非常符合程式設計師的習慣。
唯一的缺點就是文件特別難找,難讀。通過對其文件的閱讀和對示例程式原始碼的分析,現在將NPlot的基
本概念整理如下:
NPlot的名稱空間包括NPlot,NPlot.Bitmap,NPlot.Web,NPlot.Web.Design,NPlot.Windows等,其中最
核心的,管理各種圖表的類都屬於NPlot名稱空間,NPlot.Bitmap針對點陣圖的管理,NPlot.Web,NPlot.W
eb.Design和NPlot.Windows則可視為NPlot圖表在Web Form和Windows Form上的容器(PlotSurface
2D)。這些容器可以拖到Form上,也可以位於其他容器之中。
二.vs2010下的圖表控制元件NPlot下載
http://files.cnblogs.com/files/hongmaju/NPlotClass.zip
三.vs2010上的配置和使用
要在應用程式中應用NPlot控制元件,首先要把所下載的NPlot.dll新增到.Net工程中。並將其新增到工具箱托盤
中。新增方式為:在工具箱上單擊右鍵,選擇“選擇項”,會出現“選擇工具箱項”對話方塊,在“.Net Framew
orks元件”屬性頁,選擇瀏覽,找到NPlot.dll新增到工具箱項。這時工具箱中會出現NPlot控制元件。在設計應
用程式介面時,可以將其拖入應用程式介面,系統會在程式碼中自動建立一個PlotSurface2D物件。
PlotSurface2D物件是NPlot圖表的容器,所有的圖表圖形,座標,標題(都繼承IDrawable介面)等各種
資訊都可以被加入PlotSurface2D。PlotSurface2D擁有一個非常重要的方法:Add。各種圖表圖形,坐
標,標題都可以通過Add加入PlotSurface2D物件,plot:為控制元件名稱,並引入空間:using NPlot;
點狀圖程式碼:
//plot.Clear();//清空 //Grid mygrid = new Grid(); //加入網格 //plot.Add(mygrid); ////Marker m = new Marker(Marker.MarkerType.FilledCircle, 6, new Pen(Color.Blue, 2.0F));//點狀圖的型別,實心圓點 //Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F));//點狀圖的型別,叉形 //PointPlot pp = new PointPlot(m); //int[] a = new int[] { 0, 1 }; //pp.OrdinateData = a; //StartStep b = new StartStep(-500.0, 10.0);//根據第一個數,可以得到相差10的兩個數 //pp.AbscissaData = b; //pp.Label = "Random"; //plot.Add(pp); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); //plot.XAxis1.IncreaseRange(0.1); //plot.YAxis1.IncreaseRange(0.1); //縮小到合適大小 //plot.Refresh();
蠟燭圖程式碼:
//plot.Clear();//清空 //int[] opens = { 1, 2, 1, 2, 1, 3 };//圓柱底座標 //double[] closes = { 2, 2, 2, 1, 2, 1 };//圓柱頂座標 //float[] lows = { 0, 1, 1, 1, 0, 0 };//下線座標 //System.Int64[] highs = { 3, 2, 3, 3, 3, 4 };//上線座標 //int[] times = { 0, 1, 2, 3, 4, 5 };//X軸位置 //CandlePlot cp = new CandlePlot(); //cp.CloseData = closes; //cp.OpenData = opens; //cp.LowData = lows; //cp.HighData = highs; //cp.AbscissaData = times; //plot.Add(cp); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); //plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); //plot.XAxis1.IncreaseRange(0.1); //plot.YAxis1.IncreaseRange(0.1); //縮小到合適大小 //plot.Refresh();
階梯狀圖程式碼:
//StepPlot sp1 = new StepPlot(); //sp1.OrdinateData = new int[] { 0, 1, 2 }; //sp1.AbscissaData = new int[] { 4, 5, 6 }; //sp1.Label = "高度"; //sp1.Pen.Width = 2; //sp1.Pen.Color = Color.Blue; //plot.Add(sp1);
柱狀圖累加圖程式碼:
//HistogramPlot hp3 = new HistogramPlot(); //hp3.AbscissaData = new int[] { 0, 1, 2 }; //hp3.OrdinateData = new int[] { 4, 5, 6 }; //hp3.BaseWidth = 0.6f; //hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade;//縱向漸變 //hp3.Filled = true; //hp3.Label = "一月"; //HistogramPlot hp4 = new HistogramPlot(); //hp4.AbscissaData = new int[] { 0, 1, 2 }; //hp4.OrdinateData = new int[] { 7, 81, 9 }; //hp4.Label = "二月"; //hp4.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;//橫向漸變 //hp4.Filled = true; //hp4.StackedTo(hp3); //plot.Add(hp3); //plot.Add(hp4);