NPlot开源画图类

时间:2023-03-09 09:22:34
NPlot开源画图类

一.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上,也可以位于其他容器之中。

NPlot开源画图类NPlot开源画图类

二.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;

NPlot开源画图类NPlot开源画图类NPlot开源画图类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);