public void PlotCandleSimple()
        {
            string lines = "Simple CandlePlot example. Demonstrates -  * Setting candle plot datapoints using arrays.";
            infoBox.Text = lines;

            plotSurface.Clear();

            FilledRegion fr = new FilledRegion(
                new VerticalLine(1.2),
                new VerticalLine(2.4));
            fr.Brush = new SolidBrush(Color.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 xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.MouseWheelZoom() );

            plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotSurface.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();
        }
        public void PlotTest()
        {
            plotSurface.Clear();

            // can plot different types.
            ArrayList l = new ArrayList();
            l.Add( (int)2 );
            l.Add( (double)1.0 );
            l.Add( (float)3.0 );
            l.Add( (int)5.0 );

            LinePlot lp1 = new LinePlot( new double[] {4.0, 3.0, 5.0, 8.0} );
            lp1.Pen = new Pen( Color.LightBlue );
            lp1.Pen.Width = 2.0f;

            //lp.AbscissaData = new StartStep( 0.0, 2.0 );

            LinePlot lp2 = new LinePlot( new double[] {2.0, 1.0, 4.0, 5.0} );
            lp2.Pen = new Pen( Color.LightBlue );
            lp2.Pen.Width = 2.0f;

            FilledRegion fr = new FilledRegion( lp1, lp2 );

            plotSurface.Add(fr);

            plotSurface.Add( new Grid() );
            plotSurface.Add(lp1);
            plotSurface.Add(lp2);

            ArrowItem a = new ArrowItem( new PointD( 2, 4 ), -50.0f, "Arrow" );
            a.HeadOffset = 5;
            a.ArrowColor = Color.Red;
            a.TextColor = Color.Purple;
            plotSurface.Add( a );

            MarkerItem m = new MarkerItem( new Marker( Marker.MarkerType.TriangleDown, 8, Color.ForestGreen ), 1.38, 2.9 );
            plotSurface.Add( m );

            plotSurface.XAxis1.TicksCrossAxis = true;

            ((LinearAxis)plotSurface.XAxis1).LargeTickValue = -4.1;
            ((LinearAxis)plotSurface.XAxis1).AutoScaleText = true;
            ((LinearAxis)plotSurface.XAxis1).TicksIndependentOfPhysicalExtent = true;
            //plotSurface.XAxis1.Label = "Hello world";
            plotSurface.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();

            /*
            plotSurface.AutoScaleTitle = false;
            plotSurface.AutoScaleAutoGeneratedAxes = true;

            plotSurface.Title = "My Title";

            double[] a = { 0, 2, 1, 4, double.NaN, double.NaN, 5, 8, 7, 9 };
            LinePlot lp = new LinePlot();
            lp.DataSource = a;
            lp.Label = "My Label";

            plotSurface.Add( lp );

            plotSurface.Legend = new Legend();
            plotSurface.Legend.AutoScaleText = false;
            plotSurface.Legend.NeverShiftAxes = true;
            plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside;
            plotSurface.Legend.VerticalEdgePlacement = Legend.Placement.Inside;
            plotSurface.Legend.XOffset = -10;
            plotSurface.Legend.YOffset = 10;
            //plotSurface.AddAxesConstraint( new AxesConstraint.EqualSpacing() );

            ((LinearAxis)plotSurface.XAxis1).Offset = 10.0;
            ((LinearAxis)plotSurface.XAxis1).Scale = 27.0;
            //((LinearAxis)plotSurface.XAxis1).TicksIndependentOfPhysicalExtent = true;
            //((LinearAxis)plotSurface.YAxis1).TicksIndependentOfPhysicalExtent = true;

            AxesConstraint.AxisPosition c1 =
                new xuzhenzhen.com.chart.AxesConstraint.AxisPosition( PlotSurface2D.YAxisPosition.Left, 100.0f );

            AxesConstraint.AspectRatio c2 =
                new AxesConstraint.AspectRatio( 5.0f, PlotSurface2D.YAxisPosition.Left );

            plotSurface.AddAxesConstraint( c1 );
            plotSurface.AddAxesConstraint( c2 );

            plotSurface.Refresh();
            */
        }
        void PlotDataSet()
        {
            string lines = "Stock Data Example. Demonstrates -  * CandlePlot, FilledRegion, LinePlot and ArrowItem IDrawables * DateTime axes * A few plot interactions. Try (a) dragging the axes (b) dragging the plot surface.";
            infoBox.Text = lines;
            plotSurface.Clear();
            //plotSurface.DateTimeToolTip = true;

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            //System.IO.Stream file =Assembly.GetExecutingAssembly().GetManifestResourceStream("ChartProject1.asx_jbh");
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PlotSurface2DDemo));
            StringReader reader = new StringReader((String)resources.GetObject("asx_jbh"));
            ds.ReadXml(reader, 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.FloralWhite, Color.GhostWhite );
            fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FromArgb(255,255,240), Color.FromArgb(240,255,255) );

            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 xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag());
            plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.AxisDrag(true));

            // make sure plot surface colors are as we expect - the wave example changes them.
            plotSurface.PlotBackColor = Color.White;
            plotSurface.BackColor = System.Drawing.SystemColors.Control;
            plotSurface.XAxis1.Color = Color.Black;
            plotSurface.YAxis1.Color = Color.Black;
            plotSurface.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();
        }
Esempio n. 4
0
        public void InitDataToChart()
        {
            //清空
            chart1.Clear();
            chart2.Clear();
            chart3.Clear();
            //垂直线
            vline = new VerticalLine(0, Color.Blue);
            //图例
            legend = new Legend();
            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left);
            legend.VerticalEdgePlacement = Legend.Placement.Inside;
            legend.HorizontalEdgePlacement = Legend.Placement.Outside;
            legend.YOffset = -5;
            legend.BorderStyle = LegendBase.BorderType.Line;
            legend.NumberItemsHorizontally = 4;
            //网格
            grid = new Grid();
            grid.HorizontalGridType = Grid.GridType.Fine;
            grid.VerticalGridType = Grid.GridType.Fine;
            grid.MajorGridPen.Color = Color.Silver;
            grid.MinorGridPen.Color = Color.Silver;
            /////区域着色////////
            fill = new FilledRegion(new VerticalLine(-1), new VerticalLine(8));
            fill.Brush = new SolidBrush(Color.FromArgb(250, 218, 169));
            /////////////////////////////////////////////
            //直线图
            sysPlot = new LinePlot();
            sysPlot.OrdinateData = sysList;
            sysPlot.AbscissaData = timeList;
            sysPlot.Color = Color.RoyalBlue;
            sysPlot.Pen.Width = 2.0f;
            sysPlot.Label = "SYS";

            diaPlot = new LinePlot();
            diaPlot.OrdinateData = diaList;
            diaPlot.AbscissaData = timeList;
            diaPlot.Color = Color.OrangeRed;
            diaPlot.Pen.Width = 2.0f;
            diaPlot.Label = "DIA";

            mapPlot = new LinePlot();
            mapPlot.OrdinateData = mapList;
            mapPlot.AbscissaData = timeList;
            mapPlot.Color = Color.Chartreuse;
            mapPlot.Pen.Width = 2.0f;
            mapPlot.Label = "MAP";

            hrPlot = new LinePlot();
            hrPlot.OrdinateData = hrList;
            hrPlot.AbscissaData = timeList;
            hrPlot.Color = Color.DarkSlateBlue;
            hrPlot.Pen.Width = 2.0f;

            sys_hrPlot = new LinePlot();
            sys_hrPlot.OrdinateData = sys_hrList;
            sys_hrPlot.AbscissaData = timeList;
            sys_hrPlot.Color = Color.Green;
            sys_hrPlot.Pen.Width = 2.0f;

            //水平线
            hline1 = new HorizontalLine(70, Color.Gray);
            hline2 = new HorizontalLine(90, Color.Gray);
            hline3 = new HorizontalLine(120, Color.Gray);
            hline4 = new HorizontalLine(140, Color.Gray);

            ///////////////////////
            chart1.Add(fill);
            chart1.Add(grid);
            chart1.Add(sysPlot);
            chart1.Add(diaPlot);
            chart1.Add(mapPlot);
            chart1.Add(hline1);
            chart1.Add(hline2);
            chart1.Add(hline3);
            chart1.Add(hline4);
            chart1.Add(vline);
            chart1.XAxis1.HideTickText = true;
            chart1.YAxis1.Label = "血压:mmHg";
            chart1.YAxis1.LabelOffsetAbsolute = true;
            chart1.YAxis1.WorldMin = chart1.YAxis1.WorldMin - 20;
            chart1.YAxis1.WorldMax = chart1.YAxis1.WorldMax + 20;
            chart1.Padding = 5;
            chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag());
            chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline());
            chart1.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60));
            chart1.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart1_InteractionOccured);
            chart1.PlotBackColor = Color.White;
            chart1.BackColor = System.Drawing.SystemColors.Control;
            chart1.XAxis1.Color = Color.Black;
            chart1.YAxis1.Color = Color.Black;
            chart1.Legend = legend;
            chart1.LegendZOrder = 1;
            chart1.Refresh();
            ///////////////////////////
            chart2.Add(fill);
            chart2.Add(grid);
            chart2.Add(hrPlot);
            chart2.Add(vline);
            chart2.XAxis1.HideTickText = true;
            chart2.YAxis1.Label = "心率:BPM";
            chart2.YAxis1.LabelOffsetAbsolute = true;
            chart2.Padding = 5;
            chart2.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60));
            chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag());
            chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline());
            chart2.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart2_InteractionOccured);
            chart2.PlotBackColor = Color.White;
            chart2.BackColor = System.Drawing.SystemColors.Control;
            chart2.XAxis1.Color = Color.Black;
            chart2.YAxis1.Color = Color.Black;
            chart2.Refresh();
            ///////////////////////////
            chart3.Add(fill);
            chart3.Add(grid);
            chart3.Add(sys_hrPlot);
            chart3.Add(vline);
            LabelAxis axis = new LabelAxis(chart3.XAxis1);
            int tick = 1;
            if (chart2.XAxis1.WorldMax - chart2.XAxis1.WorldMin > 30)
                tick = 2;
            for (int i = (int)chart2.XAxis1.WorldMin; i <= chart2.XAxis1.WorldMax; i+=tick)
            {
                int j = i % 24;
                if (j < 0) j += 24;
                axis.AddLabel(Convert.ToString(j), i);
            }
            chart3.XAxis1 = axis;
            chart3.XAxis1.Label = "Time:Hour";
            chart3.YAxis1.Label = "SYS*PR/100";
            chart3.YAxis1.LabelOffsetAbsolute = true;
            chart3.Padding = 5;
            chart3.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60));
            chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag());
            chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline());
            chart3.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart3_InteractionOccured);
            chart3.PlotBackColor = Color.White;
            chart3.BackColor = System.Drawing.SystemColors.Control;
            chart3.XAxis1.Color = Color.Black;
            chart3.YAxis1.Color = Color.Black;
            chart3.Refresh();
            SetStatusNow();
        }