예제 #1
0
        public CandlePlotSample()
            : base()
        {
            infoText = "";
            infoText += "Simple CandlePlot example. Demonstrates - \n";
            infoText += " * Setting candle plot datapoints using arrays \n";

            plotCanvas.Clear();

            //FilledRegion fr = new FilledRegion (new VerticalLine (1.2), new VerticalLine (2.4));
            //fr.Brush = Brushes.BlanchedAlmond;
            //plotCanvas.Add (fr);

            // note that arrays can be of any type you like.
            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;
            plotCanvas.Add (cp);

            HorizontalLine line = new HorizontalLine (1.2);
            line.LengthScale = 0.89;
            plotCanvas.Add (line, -10);

            //VerticalLine line2 = new VerticalLine ( 1.2 );
            //line2.LengthScale = 0.89;
            //plotCanvas.Add (line2);

            plotCanvas.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotCanvas.Refresh ();

            plotCanvas.Legend = new Legend(	);
            plotCanvas.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top.

            PackStart (plotCanvas.Canvas, true);
            Label la = new Label (infoText);
            PackStart (la);
        }
예제 #2
0
파일: PlotCandle.cs 프로젝트: sanyu1/NPlot
        public PlotCandle()
        {
            infoText = "";
            infoText += "Simple CandlePlot example. Demonstrates - \n";
            infoText += " * Setting candle plot datapoints using arrays \n";
            infoText += " * Plot Zoom interaction using MouseWheel ";

            plotSurface.Clear();

            FilledRegion fr = new FilledRegion(
                new VerticalLine(1.2),
                new VerticalLine(2.4));
            fr.Brush = Brushes.BlanchedAlmond;
            plotSurface.Add(fr);

            // note that arrays can be of any type you like.
            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;
            plotSurface.Add(cp);

            HorizontalLine line = new HorizontalLine( 1.2 );
            line.LengthScale = 0.89f;
            plotSurface.Add( line, -10 );

            VerticalLine line2 = new VerticalLine( 1.2 );
            line2.LengthScale = 0.89f;
            plotSurface.Add( line2 );

            plotSurface.AddInteraction (new PlotZoom());

            plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotSurface.Refresh();
        }
예제 #3
0
파일: PlotDataset.cs 프로젝트: sanyu1/NPlot
        public PlotDataset()
        {
            infoText = "";
            infoText += "Stock Dataset Sample. Demonstrates - \n";
            infoText += " * CandlePlot, FilledRegion, LinePlot and ArrowItem IDrawables \n";
            infoText += " * DateTime axes \n";
            infoText += " * Horizontal Drag Interaction - try dragging (and Ctrl-dragging) the plot surface \n";
            infoText += " * Axis Drag Interaction - try dragging in the horizontal and vertical Axis areas";

            plotSurface.Clear();
            // [NOTIMP] plotSurface.DateTimeToolTip = true;

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream( "GtkTest.Resources.asx_jbh.xml" );
            ds.ReadXml( file, System.Data.XmlReadMode.ReadSchema );
            DataTable dt = ds.Tables[0];
            // DataView dv = new DataView( dt );

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();
            cp.DataSource = dt;
            cp.AbscissaData = "Date";
            cp.OpenData = "Open";
            cp.LowData = "Low";
            cp.HighData = "High";
            cp.CloseData = "Close";
            cp.BearishColor = Color.Red;
            cp.BullishColor = Color.Green;
            cp.Style = CandlePlot.Styles.Filled;

            // calculate 10 day moving average and 2*sd line
            ArrayList av10 = new ArrayList();
            ArrayList sd2_10 = new ArrayList();
            ArrayList sd_2_10 = new ArrayList();
            ArrayList dates = new ArrayList();
            for (int i=0; i<dt.Rows.Count-10; ++i)
            {
                float sum = 0.0f;
                for (int j=0; j<10; ++j)
                {
                    sum += (float)dt.Rows[i+j]["Close"];
                }
                float average = sum / 10.0f;
                av10.Add( average );
                sum = 0.0f;
                for (int j=0; j<10; ++j)
                {
                    sum += ((float)dt.Rows[i+j]["Close"]-average)*((float)dt.Rows[i+j]["Close"]-average);
                }
                sum /= 10.0f;
                sum = 2.0f*(float)Math.Sqrt( sum );
                sd2_10.Add( average + sum );
                sd_2_10.Add( average - sum );
                dates.Add( (DateTime)dt.Rows[i+10]["Date"] );
            }

            // and a line plot of close values.
            LinePlot av = new LinePlot();
            av.OrdinateData = av10;
            av.AbscissaData = dates;
            av.Color = Color.LightGray;
            av.Pen.Width = 2.0f;

            LinePlot top = new LinePlot();
            top.OrdinateData = sd2_10;
            top.AbscissaData = dates;
            top.Color = Color.LightSteelBlue;
            top.Pen.Width = 2.0f;

            LinePlot bottom = new LinePlot();
            bottom.OrdinateData = sd_2_10;
            bottom.AbscissaData = dates;
            bottom.Color = Color.LightSteelBlue;
            bottom.Pen.Width = 2.0f;

            FilledRegion fr = new FilledRegion( top, bottom );
            fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FromArgb(255,255,240), Color.FromArgb(240,255,255) );
            plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            plotSurface.Add( fr );

            plotSurface.Add( new Grid() );

            plotSurface.Add( av );
            plotSurface.Add( top );
            plotSurface.Add( bottom );
            plotSurface.Add( cp );

            // now make an arrow...
            ArrowItem arrow = new ArrowItem( new PointD( ((DateTime)dt.Rows[60]["Date"]).Ticks, 2.28 ), -80, "An interesting flat bit" );
            arrow.ArrowColor = Color.DarkBlue;
            arrow.PhysicalLength = 50;

            plotSurface.Add (arrow);

            plotSurface.Title = "AU:JBH";
            plotSurface.XAxis1.Label = "Date / Time";
            plotSurface.XAxis1.WorldMin += plotSurface.XAxis1.WorldLength / 4.0;
            plotSurface.XAxis1.WorldMax -= plotSurface.XAxis1.WorldLength / 2.0;
            plotSurface.YAxis1.Label = "Price [$]";

            plotSurface.XAxis1 = new TradingDateTimeAxis( plotSurface.XAxis1 );

            plotSurface.AddInteraction (new PlotDrag(true,false));
            plotSurface.AddInteraction (new AxisDrag());

            // make sure plot surface colors are as we expect - the wave example changes them.
            plotSurface.PlotBackColor = Color.White;
            plotSurface.XAxis1.Color = Color.Black;
            plotSurface.YAxis1.Color = Color.Black;

            plotSurface.Refresh();
        }
예제 #4
0
        public FinancialDemo()
            : base("Multiple linked plot demo")
        {
            //
            // Gtk Window Setup
            //
            InitializeComponent();

            costPS.Clear();

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("GtkTest.Resources.asx_jbh.xml");
            ds.ReadXml(file, System.Data.XmlReadMode.ReadSchema);
            DataTable dt = ds.Tables[0];
            // DataView dv = new DataView(dt);

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();
            cp.DataSource = dt;
            cp.AbscissaData = "Date";
            cp.OpenData = "Open";
            cp.LowData = "Low";
            cp.HighData = "High";
            cp.CloseData = "Close";
            cp.BearishColor = Color.Red;
            cp.BullishColor = Color.Green;
            cp.Style = CandlePlot.Styles.Filled;
            costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            costPS.Add(new Grid());
            costPS.Add(cp);
            costPS.Title = "AU:JBH";
            costPS.YAxis1.Label = "Price [$]";
            costPS.YAxis1.LabelOffset = 40;
            costPS.YAxis1.LabelOffsetAbsolute = true;
            costPS.XAxis1.HideTickText = true;
            costPS.SurfacePadding = 5;

            costPS.AddInteraction(new NPlot.PlotDrag(true,true));
            costPS.AddInteraction(new NPlot.AxisDrag());
            costPS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(costPS_InteractionOccurred);
            costPS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60));

            costPS.Refresh();

            PointPlot pp = new PointPlot();
            pp.Marker = new Marker(Marker.MarkerType.Square, 0);
            pp.Marker.Pen = new Pen(Color.Red, 5.0f);
            pp.Marker.DropLine = true;
            pp.DataSource = dt;
            pp.AbscissaData = "Date";
            pp.OrdinateData = "Volume";
            volumePS.Add(pp);
            volumePS.YAxis1.Label = "Volume";
            volumePS.YAxis1.LabelOffsetAbsolute = true;
            volumePS.YAxis1.LabelOffset = 40;
            volumePS.SurfacePadding = 5;

            volumePS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60));
            volumePS.AddInteraction(new NPlot.AxisDrag());
            volumePS.AddInteraction(new NPlot.PlotDrag(true,false));
            volumePS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(volumePS_InteractionOccurred);
             	        volumePS.PreRefresh += new NPlot.InteractivePlotSurface2D.PreRefreshHandler(volumePS_PreRefresh);

             	        volumePS.Refresh();
        }
예제 #5
0
        void PlotCandle()
        {
            plotSurface.Clear();

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream( "NPlotDemo.resources.asx_jbh.xml" );
            ds.ReadXml( file, System.Data.XmlReadMode.ReadSchema );
            DataTable dt = ds.Tables[0];

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();
            cp.DataSource = dt;
            cp.AbscissaData = "Date";
            cp.OpenData = "Open";
            cp.LowData = "Low";
            cp.HighData = "High";
            cp.CloseData = "Close";
            cp.BearishColor = Color.Red;
            cp.BullishColor = Color.Green;
            cp.StickWidth = 3;
            cp.Color = Color.DarkBlue;

            plotSurface.Add( new Grid() );
            plotSurface.Add( cp );

            plotSurface.Title = "AU:JBH";
            plotSurface.XAxis1.Label = "Date / Time";
            plotSurface.YAxis1.Label = "Price [$]";

            plotSurface.Refresh();
        }
예제 #6
0
파일: MainForm.cs 프로젝트: mono/nplot-gtk
        void PlotDataSet()
        {
            plotSurface.Clear();

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream( "NPlotDemo.resources.asx_jbh.xml" );
            ds.ReadXml( file, System.Data.XmlReadMode.ReadSchema );
            DataTable dt = ds.Tables[0];

            // create CandlePlot.
            CandlePlot cp = new CandlePlot();
            cp.DataSource = dt;
            cp.AbscissaData = "Date";
            cp.OpenData = "Open";
            cp.LowData = "Low";
            cp.HighData = "High";
            cp.CloseData = "Close";
            cp.BearishColor = Color.Red;
            cp.BullishColor = Color.Green;
            cp.Style = CandlePlot.Styles.Filled;

            // calculate 10 day moving average and 2*sd line
            ArrayList av10 = new ArrayList();
            ArrayList sd2_10 = new ArrayList();
            ArrayList sd_2_10 = new ArrayList();
            ArrayList dates = new ArrayList();
            for (int i=0; i<dt.Rows.Count-10; ++i)
            {
                float sum = 0.0f;
                for (int j=0; j<10; ++j)
                {
                    sum += (float)dt.Rows[i+j]["Close"];
                }
                float average = sum / 10.0f;
                av10.Add( average );
                sum = 0.0f;
                for (int j=0; j<10; ++j)
                {
                    sum += ((float)dt.Rows[i+j]["Close"]-average)*((float)dt.Rows[i+j]["Close"]-average);
                }
                sum /= 10.0f;
                sum = 2.0f*(float)Math.Sqrt( sum );
                sd2_10.Add( average + sum );
                sd_2_10.Add( average - sum );
                dates.Add( (DateTime)dt.Rows[i+10]["Date"] );
            }

            // and a line plot of close values.
            LinePlot av = new LinePlot();
            av.OrdinateData = av10;
            av.AbscissaData = dates;
            av.Color = Color.LightGray;
            av.Pen.Width = 2.0f;

            LinePlot top = new LinePlot();
            top.OrdinateData = sd2_10;
            top.AbscissaData = dates;
            top.Color = Color.LightSteelBlue;
            top.Pen.Width = 2.0f;

            LinePlot bottom = new LinePlot();
            bottom.OrdinateData = sd_2_10;
            bottom.AbscissaData = dates;
            bottom.Color = Color.LightSteelBlue;
            bottom.Pen.Width = 2.0f;

            FilledRegion fr = new FilledRegion( top, bottom );
            //fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FloralWhite, Color.GhostWhite );
            fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FromArgb(255,255,240), Color.FromArgb(240,255,255) );
            plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            plotSurface.Add( fr );

            plotSurface.Add( new Grid() );

            plotSurface.Add( av );
            plotSurface.Add( top );
            plotSurface.Add( bottom );
            plotSurface.Add( cp );

            // now make an arrow...
            ArrowItem arrow = new ArrowItem( new PointD( ((DateTime)dt.Rows[60]["Date"]).Ticks, 2.28 ), -80, "An interesting flat bit" );
            arrow.ArrowColor = Color.DarkBlue;
            arrow.PhysicalLength = 50;

            plotSurface.Add( arrow );

            plotSurface.Title = "AU:JBH";
            plotSurface.XAxis1.Label = "Date / Time";
            plotSurface.YAxis1.Label = "Price [$]";

            plotSurface.Refresh();

            plotSurface.Refresh();
        }