威尼斯人线上娱乐

行使NPlot绘图技巧,下哪些用NPlot绘制期货股票K线图

6 4月 , 2019  

威尼斯人线上娱乐 1

威尼斯人线上娱乐 2

 

  原文 C#行使NPlot绘图技巧,下哪些用NPlot绘制期货股票K线图。
使用NPlot绘图技巧

[简介]

[简介]

先是要将下载的NPlot.dll加到工具箱里,拖1个控件到窗体上,注解using
NPlot。

  图表控件平昔是很难找的,尤其是免费又有力的。NPlot是一款1二分难能可贵的.Net平台下的图形控件,能做各类曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也不行契合程序员的习惯。唯壹的弱点正是文档越发难找,难读。通过对其文书档案的读书和对示例程序源代码的辨析,将来将NPlot的基本概念整理如下:

用作一名专业程序化交易者,编制程序是多个程序员的基本功,本文是笔者在做的三个期货CTP项目中关于K线绘图的一部分,偿试类MT4中图表
设计而写,在编写绘图时,查阅了有关资料,感觉依旧用NPlot的那一个图片控件相比较好,特点是:免费,能够用于winform程序,而且速度相比快,能够实时动态显示图表数据,上边就进来主题.

用作一名专业程序化交易者,编制程序是三个程序员的基础,本文是作者在做的三个期货CTP项目中有关K线绘图的1有个别,偿试类MT四中图表
设计而写,在编写绘图时,查阅了有关质感,感觉还是用NPlot的这么些图形控件相比较好,特点是:免费,能够用来winform程序,而且速度比较快,能够实时动态展现图表数据,下边就进去宗旨.

一、入门

一.
对所绘的图举行打字与印刷与封存

威尼斯人线上娱乐 3威尼斯人线上娱乐 4

private void print()
{
    myPlot.Print(true);
}
private void save()
{
    saveFileDialog1.Filter = "位图 (*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg;*.jpeg;*,jpe|Gif(*.gif)|*.gif|Tiff(*.tiff)|*.tiff|Png(*.png)|*.png|Exif(*.exif)|*.exif| 所有文件(*.*)|*.*";
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
       try
        {
            int h = myPlot.Size.Height;
            int w = myPlot.Size.Width;
            Bitmap bm = new Bitmap(w, h);
            Bitmap bm1 = new Bitmap(w, h);
            Rectangle rt = new Rectangle(1, 1, w, h);
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.CreatePrompt = true;
            myPlot.DrawToBitmap(bm, rt);
            if (saveFileDialog1.FilterIndex == 1)
            {
                bm.Save(saveFileDialog1.FileName);
            }
            if (saveFileDialog1.FilterIndex == 2)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
            }
            if (saveFileDialog1.FilterIndex == 3)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Gif);
            }
            if (saveFileDialog1.FilterIndex == 4)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Tiff);
            }
            if (saveFileDialog1.FilterIndex == 5)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Png);
            }
            if (saveFileDialog1.FilterIndex == 6)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Exif);
            }
        }
        catch (Exception MyEx)
        {
            MessageBox.Show(MyEx.ToString(), "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}

View Code

 

   
NPlot的命名空间包含NPlot,NPlot.Bitmap,NPlot.Web,NPlot.Web.Design,NPlot.Windows等,在那之中最基本的,管理各样图片的类都属于NPlot命名空间,NPlot.Bitmap针对位图的军管,NPlot.Web,NPlot.Web.Design和NPlot.Windows则可说是NPlot图表在Web
Form和Windows
Form上的器皿(PlotSurface2D)。这几个器皿能够拖到Form上,也能够放在其余容器之中。

[内容]

[内容]

二. 加大减少

private void changeSize()
{
    this.myPlot.XAxis1.IncreaseRange(0.1);
    this.myPlot.YAxis1.IncreaseRange(0.1); //缩小
    this.myPlot.XAxis1.IncreaseRange(-0.1);
    this.myPlot.YAxis1.IncreaseRange(-0.1); //放大
    this.myPlot.Refresh();
}

 

   
要在应用程序中运用NPlot控件,首先要把所下载的NPlot.dll添加到.Net工程中。并将其添加到工具箱托盘中。添加艺术为:在工具箱上单击右键,选拔“选取项”,会冒出“选用工具箱项”对话框,在“.Net
Frameworks组件”属性页,选择浏览,找到NPlot.dll添加到工具箱项。那时工具箱中会出现NPlot控件。在统一筹划应用程序界面时,能够将其拖入应用程序界面,系统会在代码中自行创制三个PlotSurface二D对象。

壹,NPlot控件相关知识简介:

壹,NPlot控件相关文化简介:

三. 种种绘图

威尼斯人线上娱乐 5威尼斯人线上娱乐 6

private void plot()
{
    this.myPlot.Clear(
    ////////标签//////////
    string[] strLabel = new string[leng];
    for (int i = 0; i < leng; i++)
        strLabel[i] = Convert.ToString(p[i]);
    LabelPointPlot labp = new LabelPointPlot();
    labp.AbscissaData = X;
    labp.OrdinateData = p;
    labp.TextData = strLabel;
    labp.LabelTextPosition = LabelPointPlot.LabelPositions.Above;
    labp.Marker = new Marker(Marker.MarkerType.Square, 8);
    labp.Marker.Color = Color.Blue;
    myPlot.Add(labp);
    myPlot.Refresh();          
    ////////网格//////////
    Grid mygrid = new Grid();
    mygrid.HorizontalGridType = Grid.GridType.Fine;
    mygrid.VerticalGridType = Grid.GridType.Fine;
    this.myPlot.Add(mygrid);
    ////////曲线,双坐标轴//////////
    ///////水平线//////////
    HorizontalLine line = new HorizontalLine(1.2);
    line.LengthScale = 0.89f;
    this.myPlot.Add(line, -10);
    ///////垂直线///////////
    VerticalLine line2 = new VerticalLine(1.2);
    line2.LengthScale = 0.89f;
    this.myPlot.Add(line2);
    ///////普通的线///////////
    LinePlot lp3 = new LinePlot();
    lp3.OrdinateData = yPW;
    lp3.AbscissaData = x;
    lp3.Pen = new Pen(Color.Orange);
    lp3.Pen.Width = 2;
    lp3.Label = " 价格";
    this.myPlot.Add(lp3);
    LinearAxis linx = (LinearAxis)myPlot.XAxis1;
    this.myPlot.XAxis1 = linx;
    LinearAxis liny = (LinearAxis)myPlot.YAxis1;
    liny.Label = "价格";
    liny.AxisColor = Color.Orange;
    liny.LabelColor = Color.Orange;
    liny.TickTextColor = Color.Orange;
    this.myPlot.YAxis1 = liny;
    LinePlot lp4 = new LinePlot();
    lp4.OrdinateData = yUw;
    lp4.AbscissaData = x;
    lp4.Pen = new Pen(Color.Green);
    lp4.Pen.Width = 2;
    lp4.Label = "销售量";
    this.myPlot.Add(lp4, PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
    LinearAxis liny2 = (LinearAxis)myPlot.YAxis2;
    liny2.WorldMax = 1.2;
    liny2.WorldMin = 0;
    liny2.Label = "销售量";
    liny2.AxisColor = Color.Green;
    liny2.LabelColor = Color.Green;
    liny2.TickTextColor = Color.Green;
    this.myPlot.YAxis2 = liny2;
    ///////图例//////////
    this.myPlot.Legend = new Legend();
    this.myPlot.Legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
    this.myPlot.Legend.NumberItemsHorizontally = 2;
    this.myPlot.Legend.HorizontalEdgePlacement = Legend.Placement.Inside;
    this.myPlot.Legend.VerticalEdgePlacement = Legend.Placement.Inside;
    this.myPlot.Legend.YOffset = 5;
    this.myPlot.Legend.XOffset = -5;
    ///////窗体移动//////////
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));
    //////累加的柱状图////////
    HistogramPlot hp3 = new HistogramPlot();
    hp3.AbscissaData = x;
    hp3.OrdinateData = yCC1;
    hp3.BaseWidth = 0.6f;
    hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade;
    hp3.Filled = true;
    hp3.Label = "一月";
    HistogramPlot hp4 = new HistogramPlot();
    hp4.AbscissaData = x;
    hp4.OrdinateData = yCC2;
    hp4.Label = "二月";
    hp4.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;
    hp4.Filled = true;
    hp4.StackedTo(hp3);
    this.myPlot.Add(hp3);
    this.myPlot.Add(hp4);
    //////阶状图////////                 
    StepPlot sp1 = new StepPlot();
    sp1.OrdinateData = yCH1;
    sp1.AbscissaData = x;
    sp1.Label = "高度";
    sp1.Pen.Width = 2;
    sp1.Pen.Color = Color.Blue;
    this.myPlot.Add(sp1);
    /////点状图////////  
    Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F));
    PointPlot pp = new PointPlot(m);
    pp.OrdinateData = a;
    pp.AbscissaData = new StartStep(-500.0, 10.0);
    pp.Label = "Random";
    this.myPlot.Add(pp);
    /////Image图////////
    double[,] map = new double[19, 19];
    for (int i = 0; i < 19; ++i)
    {
        for (int j = 0; j < 19; ++j)
        {
            map[i, j] = Convert.ToDouble(tokens[i * 19 + j], new
                System.Globalization.CultureInfo("en-US"));
        }
    }
    ImagePlot ip = new ImagePlot(map, -9.0f, 1.0f, -9.0f, 1.0f);
    ip.Gradient = new LinearGradient(Color.Gold, Color.Black);
    this.myPlot.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.RubberBandSelection());
    this.myPlot.Add(ip);
    ///////蜡烛图///////////
    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 };
    CandlePlot cp = new CandlePlot();
    cp.CloseData = closes;
    cp.OpenData = opens;
    cp.LowData = lows;
    cp.HighData = highs;
    cp.AbscissaData = times;
    this.myPlot.Add(cp);
    /////对数坐标轴////////    

    // x axis
    LogAxis logax = new LogAxis(plotSurface.XAxis1);
    logax.WorldMin = xmin;
    logax.WorldMax = xmax;
    logax.AxisColor = Color.Red;
    logax.LabelColor = Color.Red;
    logax.TickTextColor = Color.Red;
    logax.LargeTickStep = 1.0f;
    logax.Label = "x";
    this.myPlot.XAxis1 = logax;
    // y axis
    LogAxis logay = new LogAxis(plotSurface.YAxis1);
    logay.WorldMin = ymin;
    logay.WorldMax = ymax;
    logay.AxisColor = Color.Red;
    logay.LabelColor = Color.Red;
    logay.TickTextColor = Color.Red;
    logay.LargeTickStep = 1.0f;
    logay.Label = "x^2";
    this.myPlot.YAxis1 = logay;
    /////字符坐标轴////////
    LabelAxis la1 = new LabelAxis(this.myPlot.XAxis1);
    string[] sX = new string [15];
    for (int i = 0; i < 15; i++)
    {
        la1.AddLabel(sX[i].ToString(), i);
    }
    la1.Label = "时间";
    la1.TickTextFont = new Font("Courier New", 10);
    la1.TicksBetweenText = true;
    this.myPlot.XAxis1 = la1;
    /////区域着色////////         
    FilledRegion fr = new FilledRegion(new VerticalLine(1.2),new VerticalLine(2.4));
    //两条线之间的区域: FilledRegion fr = new FilledRegion(lp1, lp2);
    fr.Brush = Brushes.BlanchedAlmond;
    this.myPlot.Add(fr);
   //////画箭头//////////
    ArrowItem a = new ArrowItem(new PointD(2, 4),360-(30-90), "Arrow");
    a.HeadOffset = 5;
    a.ArrowColor = Color.Red;
    a.TextColor = Color.Purple;
    this.myPlot.Add(a);

    this.myPlot.Refresh();
}

View Code

 

   
PlotSurface二D对象是NPlot图表的容器,全部的图纸图形,坐标,标题(都继承IDrawable接口)等各样音讯都足以被参与PlotSurface贰D。PlotSurface2D拥有三个优秀重要的点子:Add。各样图片图形,坐标,题目都得以透过Add参与PlotSurface2D对象。

图表控件从来是很难找的,尤其是免费又有力的。NPlot是一款尤其难得的.Net平台下的图纸控件,能做各类曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也尤其适合程序员的习惯。唯一的短处正是文书档案尤其难找,难读。通过对其文书档案的阅读和对示例程序源代码的分析,未来将NPlot的基本概念整理如下:

图表控件一贯是很难找的,特别是免费又有力的。NPlot是壹款卓殊难得的.Net平台下的图纸控件,能做各样曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也格外吻合程序员的习惯。唯1的毛病正是文书档案尤其难找,难读。通过对其文书档案的翻阅和对示例程序源代码的分析,未来将NPlot的基本概念整理如下:

贰、图表控件­­­NPlot的基本用法

  图表控件一直是很难找的,尤其是免费又有力的。NPlot是1款越发宝贵的.Net平台下的图形控件,能做各个曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也尤其适合程序员的习惯。
唯1的缺点便是文书档案特别难找,难读。通过对其文书档案的阅读和对示例程序源代码的分析,未来将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二D)。那一个器皿能够拖到Form上,也足以放在其余容器之中。

 

威尼斯人线上娱乐 7 
威尼斯人线上娱乐 8

笔者们能够透过下边不难的代码示例来精通NPlot的中坚用法:

 

 

图片控件­­­NPlot下载

  Download
Link

 

   
NPlot的命名空间包蕴NPlot,NPlot.Bitmap,NPlot.Web,NPlot.Web.Design,NPlot.Windows等,个中最主旨的,管理各个图片的类都属于NPlot命名空间,NPlot.Bitmap针对位图的军管,NPlot.Web,NPlot.Web.Design和NPlot.Windows则可视为NPlot图表在Web
Form和Windows
Form上的容器(PlotSurface二D)。这一个器皿能够拖到Form上,也足以置身其余容器之中。

   
NPlot的命名空间包涵NPlot,NPlot.Bitmap,NPlot.Web,NPlot.Web.Design,NPlot.Windows等,当中最基本的,管理种种图片的类都属于NPlot命名空间,NPlot.Bitmap针对位图的军管,NPlot.Web,NPlot.Web.Design和NPlot.Windows则可说是NPlot图表在Web
Form和Windows
Form上的器皿(PlotSurface贰D)。这些器皿能够拖到Form上,也能够放在其余容器之中。

Visual Studio上的布署和利用

  要在应用程序中动用NPlot控件,首先要把所下载的NPlot.dll添加到.Net工程中。并将其添加到工具箱托盘中。添加办法为:在工具箱上单击右键,选择“选用项”,会油可是生“选取工具箱项”对话框,在“.Net
Framew
orks组件”属性页,选拔浏览,找到NPlot.dll添加到工具箱项。那时工具箱中会出现NPlot控件。在设计应用程序界面时,能够将其拖入应用程序界面,系统会在代码中自行创造2个PlotSurface二D对象。PlotSurface二D对象是NPlot图表的器皿,全体的图形图形,坐标,标题(都继承IDrawable接口)等各个消息都得以被参加PlotSurface二D。

  PlotSurface二D拥有几个充裕关键的不贰秘籍:Add。各个图片图形,坐标,标题都足以经过Add加入PlotSurface贰D对象,plot:为控件名称,并引进空间:using
NPlot;

威尼斯人线上娱乐 9威尼斯人线上娱乐 10威尼斯人线上娱乐 11威尼斯人线上娱乐 12

点状图代码:

威尼斯人线上娱乐 13威尼斯人线上娱乐 14

//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();

View Code

 

蜡烛图代码:

威尼斯人线上娱乐 15威尼斯人线上娱乐 16

//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();

View Code

 

阶梯状图代码:

//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);

 

 

 

 

参照小说

  1. C#
    使用NPlot绘图技巧

2.  NPlot开源画图类

 

public void plotline()
{
// --- Plotting ---
    plot.Clear();
// --- Grid Code ---
    Grid mygrid = new Grid();
    mygrid.HorizontalGridType = Grid.GridType.None;
    mygrid.VerticalGridType = Grid.GridType.Fine;
    plot.Add(mygrid);
    plot.Title = "Test";
    StepPlot line = new StepPlot();
    line.Pen = new Pen (Color.Red, 1);
    line.OrdinateData = new int [] {0, 1, 0, 1, 1, 0};
    line.HideVerticalSegments = false;
    plot.Add(line);
    plot.Refresh();
    return;
}

 

 

Grid对象和StepPlot对象都以NPlot命名空间中的对象,都连任于NPlot.IDrawable,都能够当做PlotSurface二D.Add函数调用,在NPlot中画图,正是把网格,坐标,图形等各个对象参与PlotSurface二D对象中,1切就那么粗略!

   
要在应用程序中利用NPlot控件,首先要把所下载的NPlot.dll添加到.Net工程中。并将其添加到工具箱托盘中。添加办法为:在工具箱上单击右键,选用“选用项”,会冒出“选取工具箱项”对话框,在“.Net
Frameworks组件”属性页,选用浏览,找到NPlot.dll添加到工具箱项。那时工具箱中会出现NPlot控件。在筹划应用程序界面时,能够将其拖入应用程序界面,系统会在代码中活动创造3个PlotSurface二D对象。

   
要在应用程序中运用NPlot控件,首先要把所下载的NPlot.dll添加到.Net工程中。并将其添加到工具箱托盘中。添加艺术为:在工具箱上单击右键,选拔“选择项”,会油但是生“接纳工具箱项”对话框,在“.Net
Frameworks组件”属性页,选取浏览,找到NPlot.dll添加到工具箱项。这时工具箱中会出现NPlot控件。在设计应用程序界面时,能够将其拖入应用程序界面,系统会在代码中自行创设一个PlotSurface贰D对象。

 

 

 

下边给出越来越多代码例子

   
PlotSurface贰D对象是NPlot图表的容器,全数的图纸图形,坐标,标题(都持续IDrawable接口)等各样音讯都能够被参与PlotSurface二D。PlotSurface二D拥有三个非凡首要的法子:Add。各样图片图形,坐标,题目都足以透过Add参与PlotSurface二D对象。

   
PlotSurface二D对象是NPlot图表的器皿,全数的图纸图形,坐标,标题(都一而再IDrawable接口)等种种音讯都得以被投入PlotSurface二D。PlotSurface二D拥有一个非凡重大的点子:Add。各个图片图形,坐标,标题都可以由此Add参预PlotSurface二D对象。

 

二.NPlot控件使用办法:

2.NPlot控件使用方法:

////////对所绘的图进行打印与保存//////////
private void print()
{
    myPlot.Print(true);
}
private void save()
{
    saveFileDialog1.Filter = "位图(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg;*.jpeg;*,jpe|Gif(*.gif)|*.gif|Tiff(*.tiff)|*.tiff|Png(*.png)|*.png|Exif(*.exif)|*.exif|所有文件(*.*)|*.*";
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
       try
        {
            int h = myPlot.Size.Height;
            int w = myPlot.Size.Width;
            Bitmap bm = new Bitmap(w, h);
            Bitmap bm1 = new Bitmap(w, h);
            Rectangle rt = new Rectangle(1, 1, w, h);
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.CreatePrompt = true;
            myPlot.DrawToBitmap(bm, rt);
            if (saveFileDialog1.FilterIndex == 1)
            {
                bm.Save(saveFileDialog1.FileName);
            }
            if (saveFileDialog1.FilterIndex == 2)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
            }
            if (saveFileDialog1.FilterIndex == 3)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Gif);
            }
            if (saveFileDialog1.FilterIndex == 4)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Tiff);
            }
            if (saveFileDialog1.FilterIndex == 5)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Png);
            }
            if (saveFileDialog1.FilterIndex == 6)
            {
                bm.Save(saveFileDialog1.FileName, ImageFormat.Exif);
            }
        }
        catch (Exception MyEx)
        {
            MessageBox.Show(MyEx.ToString(), "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }
}

///放大缩小
private void changeSize()
{
    this.myPlot.XAxis1.IncreaseRange(0.1);
    this.myPlot.YAxis1.IncreaseRange(0.1); //缩小
    this.myPlot.XAxis1.IncreaseRange(-0.1);
    this.myPlot.YAxis1.IncreaseRange(-0.1); //放大
    this.myPlot.Refresh();
}
/////////各种绘图//////////         
private void plot()
{
    this.myPlot.Clear(
    ////////标签//////////
    string[] strLabel = new string[leng];
    for (int i = 0; i < leng; i++)
        strLabel[i] = Convert.ToString(p[i]);
    LabelPointPlot labp = new LabelPointPlot();
    labp.AbscissaData = X;
    labp.OrdinateData = p;
    labp.TextData = strLabel;
    labp.LabelTextPosition = LabelPointPlot.LabelPositions.Above;
    labp.Marker = new Marker(Marker.MarkerType.Square, 8);
    labp.Marker.Color = Color.Blue;
    myPlot.Add(labp);
    myPlot.Refresh();           
    ////////网格//////////
    Grid mygrid = new Grid();
    mygrid.HorizontalGridType = Grid.GridType.Fine;
    mygrid.VerticalGridType = Grid.GridType.Fine;
    this.myPlot.Add(mygrid);
    ////////曲线,双坐标轴//////////
    ///////水平线//////////
    HorizontalLine line = new HorizontalLine(1.2);
    line.LengthScale = 0.89f;
    this.myPlot.Add(line, -10);
    ///////垂直线///////////
    VerticalLine line2 = new VerticalLine(1.2);
    line2.LengthScale = 0.89f;
    this.myPlot.Add(line2);
    ///////普通的线///////////
    LinePlot lp3 = new LinePlot();
    lp3.OrdinateData = yPW;
    lp3.AbscissaData = x;
    lp3.Pen = new Pen(Color.Orange);
    lp3.Pen.Width = 2;
    lp3.Label = " 价格";
    this.myPlot.Add(lp3);
    LinearAxis linx = (LinearAxis)myPlot.XAxis1;
    this.myPlot.XAxis1 = linx;
    LinearAxis liny = (LinearAxis)myPlot.YAxis1;
    liny.Label = "价格";
    liny.AxisColor = Color.Orange;
    liny.LabelColor = Color.Orange;
    liny.TickTextColor = Color.Orange;
    this.myPlot.YAxis1 = liny;

    LinePlot lp4 = new LinePlot();
    lp4.OrdinateData = yUw;
    lp4.AbscissaData = x;
    lp4.Pen = new Pen(Color.Green);
    lp4.Pen.Width = 2;
    lp4.Label = "销售量";
    this.myPlot.Add(lp4, PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
    LinearAxis liny2 = (LinearAxis)myPlot.YAxis2;
    liny2.WorldMax = 1.2;
    liny2.WorldMin = 0;
    liny2.Label = "销售量";
    liny2.AxisColor = Color.Green;
    liny2.LabelColor = Color.Green;
    liny2.TickTextColor = Color.Green;
    this.myPlot.YAxis2 = liny2;
    ///////图例//////////
    this.myPlot.Legend = new Legend();
    this.myPlot.Legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);
    this.myPlot.Legend.NumberItemsHorizontally = 2;
    this.myPlot.Legend.HorizontalEdgePlacement = Legend.Placement.Inside;
    this.myPlot.Legend.VerticalEdgePlacement = Legend.Placement.Inside;
    this.myPlot.Legend.YOffset = 5;
    this.myPlot.Legend.XOffset = -5;
    ///////窗体移动//////////
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));
    //////累加的柱状图////////
    HistogramPlot hp3 = new HistogramPlot();
    hp3.AbscissaData = x;
    hp3.OrdinateData = yCC1;
    hp3.BaseWidth = 0.6f;
    hp3.RectangleBrush = RectangleBrushes.Vertical.FaintBlueFade;
    hp3.Filled = true;
    hp3.Label = "一月";
    HistogramPlot hp4 = new HistogramPlot();
    hp4.AbscissaData = x;
    hp4.OrdinateData = yCC2;
    hp4.Label = "二月";
    hp4.RectangleBrush = RectangleBrushes.Horizontal.FaintGreenFade;
    hp4.Filled = true;
    hp4.StackedTo(hp3);
    this.myPlot.Add(hp3);
    this.myPlot.Add(hp4);
    //////阶状图////////                  
    StepPlot sp1 = new StepPlot();
    sp1.OrdinateData = yCH1;
    sp1.AbscissaData = x;
    sp1.Label = "高度";
    sp1.Pen.Width = 2;
    sp1.Pen.Color = Color.Blue;
    this.myPlot.Add(sp1);
    /////点状图////////   
    Marker m = new Marker(Marker.MarkerType.Cross1, 6, new Pen(Color.Blue, 2.0F));
    PointPlot pp = new PointPlot(m);
    pp.OrdinateData = a;
    pp.AbscissaData = new StartStep(-500.0, 10.0);
    pp.Label = "Random";
    this.myPlot.Add(pp);
    /////Image图////////
    double[,] map = new double[19, 19];
    for (int i = 0; i < 19; ++i)
    {
        for (int j = 0; j < 19; ++j)
        {
            map[i, j] = Convert.ToDouble(tokens[i * 19 + j], new
                System.Globalization.CultureInfo("en-US"));
        }
    }
    ImagePlot ip = new ImagePlot(map, -9.0f, 1.0f, -9.0f, 1.0f);
    ip.Gradient = new LinearGradient(Color.Gold, Color.Black);
    this.myPlot.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
    this.myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.RubberBandSelection());
    this.myPlot.Add(ip);
    ///////蜡烛图///////////
    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 };
    CandlePlot cp = new CandlePlot();
    cp.CloseData = closes;
    cp.OpenData = opens;
    cp.LowData = lows;
    cp.HighData = highs;
    cp.AbscissaData = times;
    this.myPlot.Add(cp);
    /////对数坐标轴////////     

    // x axis
    LogAxis logax = new LogAxis(plotSurface.XAxis1);
    logax.WorldMin = xmin;
    logax.WorldMax = xmax;
    logax.AxisColor = Color.Red;
    logax.LabelColor = Color.Red;
    logax.TickTextColor = Color.Red;
    logax.LargeTickStep = 1.0f;
    logax.Label = "x";
    this.myPlot.XAxis1 = logax;
    // y axis
    LogAxis logay = new LogAxis(plotSurface.YAxis1);
    logay.WorldMin = ymin;
    logay.WorldMax = ymax;
    logay.AxisColor = Color.Red;
    logay.LabelColor = Color.Red;
    logay.TickTextColor = Color.Red;
    logay.LargeTickStep = 1.0f;
    logay.Label = "x^2";
    this.myPlot.YAxis1 = logay;
    /////字符坐标轴////////
    LabelAxis la1 = new LabelAxis(this.myPlot.XAxis1);
    string[] sX = new string [15];
    for (int i = 0; i < 15; i++)
    {
        la1.AddLabel(sX[i].ToString(), i);
    }
    la1.Label = "时间";
    la1.TickTextFont = new Font("Courier New", 10);
    la1.TicksBetweenText = true;
    this.myPlot.XAxis1 = la1;
    /////区域着色////////          
    FilledRegion fr = new FilledRegion(new VerticalLine(1.2),new VerticalLine(2.4));
    //两条线之间的区域: FilledRegion fr = new FilledRegion(lp1, lp2);
    fr.Brush = Brushes.BlanchedAlmond;
    this.myPlot.Add(fr);
   //////画箭头//////////
    ArrowItem a = new ArrowItem(new PointD(2, 4),360-(30-90), "Arrow");
    a.HeadOffset = 5;
    a.ArrowColor = Color.Red;
    a.TextColor = Color.Purple;
    this.myPlot.Add(a);

    this.myPlot.Refresh();
}

1.下载NPlot控件文件:NPlpt.dll(内含表明文书档案及源码)下载

1.下载NPlot控件文件:NPlpt.dll(内含表达文书档案及源码)下载

 

2.新建C#项目,如candlePlot

2.新建C#项目,如candlePlot

叁.右击工具箱中菜单:选用项–>在弹出的选项工具箱项中.net框架上对话框–>浏览按钮–>找到刚才下载的NPlot.dll文件–>选中打开

③.右击工具箱中菜单:接纳项–>在弹出的取舍工具箱项中.net框架上对话框–>浏览按钮–>找到刚才下载的NPlot.dll文件–>选中打开

四.在.net
Framework组件中找到NPlot程序集中的多少个零部件plotsurfase二d都入选,就添加到工具箱中了

4.在.net
Framework组件中找到NPlot程序集中的七个零部件plotsurfase二d都入选,就添加到工具箱中了

5.拖plotsurfase二d控件到窗体上,命名myPlot,申明using NPlot;

伍.拖plotsurfase贰d控件到窗体上,命名myPlot,注解using NPlot;

下边放置蜡烛图绘制的主导代码:

威尼斯人线上娱乐 ,上边放置蜡烛图绘制的中坚代码:

 

 

 1         /////////各种绘图//////////         
 2         private void plot()
 3         {
 4             this.myPlot.Clear();
 7             ////////网格//////////
 8             Grid mygrid = new Grid();
 9             mygrid.HorizontalGridType = Grid.GridType.Fine;
10             mygrid.VerticalGridType = Grid.GridType.Fine;
11             this.myPlot.Add(mygrid);
1213             ///////水平线//////////
14             HorizontalLine line = new HorizontalLine(10);
15             line.LengthScale = 2.89f;
16             //line.OrdinateValue = 2;
17             this.myPlot.Add(line, 10);
18             ///////垂直线///////////
19             VerticalLine line2 = new VerticalLine(10);
20             line2.LengthScale = 0.89f;
21             this.myPlot.Add(line2);
22 
23 
24             ///////蜡烛图///////////
25             int[] opens = { 1, 2, 1, 2, 1, 3 };
26             double[] closes = { 2, 2, 2, 1, 2, 1 };
27             float[] lows = { 1, 1, 1, 1, 1, 1 };
28             System.Int64[] highs = { 3, 2, 3, 3, 3, 4 };
29             int[] times = { 0, 1, 2, 3, 4, 5 };
30             CandlePlot cp = new CandlePlot();
31             cp.CloseData = closes;
32             cp.OpenData = opens;
33             cp.LowData = lows;
34             cp.HighData = highs;
35             cp.AbscissaData = times;
36             this.myPlot.Add(cp);
37 
            this.myPlot.Refresh();
62         }
 1         /////////各种绘图//////////         
 2         private void plot()
 3         {
 4             this.myPlot.Clear();
 7             ////////网格//////////
 8             Grid mygrid = new Grid();
 9             mygrid.HorizontalGridType = Grid.GridType.Fine;
10             mygrid.VerticalGridType = Grid.GridType.Fine;
11             this.myPlot.Add(mygrid);
1213             ///////水平线//////////
14             HorizontalLine line = new HorizontalLine(10);
15             line.LengthScale = 2.89f;
16             //line.OrdinateValue = 2;
17             this.myPlot.Add(line, 10);
18             ///////垂直线///////////
19             VerticalLine line2 = new VerticalLine(10);
20             line2.LengthScale = 0.89f;
21             this.myPlot.Add(line2);
22 
23 
24             ///////蜡烛图///////////
25             int[] opens = { 1, 2, 1, 2, 1, 3 };
26             double[] closes = { 2, 2, 2, 1, 2, 1 };
27             float[] lows = { 1, 1, 1, 1, 1, 1 };
28             System.Int64[] highs = { 3, 2, 3, 3, 3, 4 };
29             int[] times = { 0, 1, 2, 3, 4, 5 };
30             CandlePlot cp = new CandlePlot();
31             cp.CloseData = closes;
32             cp.OpenData = opens;
33             cp.LowData = lows;
34             cp.HighData = highs;
35             cp.AbscissaData = times;
36             this.myPlot.Add(cp);
37 
            this.myPlot.Refresh();
62         }


相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图