コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        void PlotCandle()
        {
            plotSurface.Clear();

            // obtain stock information from xml file
            DataSet ds = new DataSet();
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream( "xuzhenzhen.com.chartDemo.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.XAxis1.LabelOffset = 0;
            plotSurface.YAxis1.LabelOffset = 0;
            plotSurface.Refresh();
        }