Exemplo n.º 1
0
        public CandleStickDemo()
            : base("Demonstration of the Candlestick Chart Type",
									"CandleStick Demo", DemoType.Bar)
        {
            GraphPane myPane = base.GraphPane;

            myPane.Title.Text = "Candlestick Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;

            for ( int i = 0; i < 50; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );
                spl.Add( pt );

                open = close;
                // Advance one day
                xDate.AddDays( 1.0 );
                // but skip the weekends
                if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                    xDate.AddDays( 2.0 );
            }

            CandleStickItem myCurve = myPane.AddCandleStick( "trades", spl, Color.Black );
            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;
            myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 );

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

            base.ZedGraphControl.AxisChange();
        }
Exemplo n.º 2
0
        public void CreateGraph_junk5( ZedGraphControl zgc )
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "Japanese Candlestick Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;

            for ( int i = 0; i < 1000; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );
                spl.Add( pt );

                open = close;
                if ( xDate.DateTime.Hour < 23 )
                    xDate.AddHours( 1.0 );
                else
                {
                    // Advance one day
                    xDate.AddHours( 1.0 );
                    // but skip the weekends
                    if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                        xDate.AddDays( 2.0 );
                }
            }

            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl );
            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;
            myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 );
            myPane.XAxis.Scale.Format = "dd-MMM-yy hh:mm";

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

            PointPairList ppl = new PointPairList();

            for ( int i = 19; i < spl.Count; i++ )
            {
                double avg = 0.0;
                for ( int j = 0; j < 20; j++ )
                    avg += spl.GetAt( i - j ).Close;
                ppl.Add( i + 1, avg / 20.0 );
            }
            LineItem item = myPane.AddCurve( "MA-20", ppl, Color.Red );
            item.IsOverrideOrdinal = true;
            item.Line.Width = 3;
            item.Symbol.Type = SymbolType.None;
            item.Line.IsSmooth = true;

            // Tell ZedGraph to calculate the axis ranges
            zgc.AxisChange();
            zgc.Invalidate();
        }
Exemplo n.º 3
0
        private void CreateGraph_StickToCurve( ZedGraphControl z1 )
        {
            PointPairList listCurve = new PointPairList();
            PointPairList listPts = new PointPairList();

            Random rand = new Random();
            double val = 155.0;
            XDate date = new XDate( 2005, 7, 1 );

            for ( int iDay = 0; iDay < 60; iDay++ )
            {
                double dv = rand.NextDouble() * 3 - 1.5;
                listCurve.Add( date, val );
                listPts.Add( date, val + dv, val );

                val += rand.NextDouble() * 0.4 - 0.3;
                date.AddDays( 1 );
            }

            GraphPane myPane = z1.GraphPane;
            myPane.XAxis.Type = AxisType.Date;

            myPane.AddCurve( "val", listCurve, Color.Red, SymbolType.None );
            LineItem scatter = myPane.AddCurve( "pts", listPts, Color.Blue, SymbolType.Diamond );
            scatter.Line.IsVisible = false;
            scatter.Symbol.Fill = new Fill( Color.White );
            scatter.Symbol.Size = 5;

            ErrorBarItem myBar = myPane.AddErrorBar( "bars", listPts, Color.Green );
            myBar.Bar.Symbol.IsVisible = false;

            z1.AxisChange();
        }
Exemplo n.º 4
0
        // OHLC Bar Test
        private void CreateGraph_OHLCBarTest( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;

            myPane.Title.Text = "OHLC Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;

            for ( int i = 0; i < 50; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );
                spl.Add( pt );

                open = close;
                // Advance one day
                //xDate.AddMinutes( 1.0 );
                xDate.AddDays( 1.0 );
                // but skip the weekends
                //if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                //	xDate.AddMinutes( 2.0 );
            }

            OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue);
            //myCurve.Bar.IsAutoSize = true;
            myCurve.Bar.Color = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            //myPane.XAxis.Type = AxisType.DateAsOrdinal;
            myPane.XAxis.Type = AxisType.Date;
            //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 );

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

            // Tell ZedGraph to calculate the axis ranges
            z1.AxisChange();
            z1.Invalidate();

            //z1.PointValueEvent += new ZedGraphControl.PointValueHandler( z1_PointValueEvent );
        }
Exemplo n.º 5
0
        // Traditional Open-High-Low-Close Bar chart
        private void CreateGraph_OHLCBar( ZedGraphControl z1 )
        {
            GraphPane myPane = z1.GraphPane;

            myPane.Title.Text = "OHLC Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is feb 1st
            XDate xDate = new XDate( 2006, 2, 1 );
            double open = 50.0;

            for ( int i = 0; i < 20; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );
                spl.Add( pt );

                open = close;
                // Advance one day
                xDate.AddDays( 1.0 );
                // but skip the weekends
                if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                    xDate.AddDays( 2.0 );
            }

            //OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Black );
            OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue );
            //myCurve.Bar.Size = 20;
            myCurve.Bar.IsAutoSize = true;
            //myCurve.Bar.PenWidth = 2;
            //myCurve.Bar.IsOpenCloseVisible = false;

            Fill fill = new Fill( Color.Red, Color.Yellow, Color.Blue );
            fill.RangeMin = 40;
            fill.RangeMax = 70;
            fill.Type = FillType.GradientByY;
            myCurve.Bar.GradientFill = fill;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;
            //myPane.XAxis.Type = AxisType.Date;
            //myPane.XAxis.Scale.MajorStep = 1.0;

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

            //BoxObj box = new BoxObj( 4, 60, 5, 50000 );
            //myPane.GraphObjList.Add( box );

            // Tell ZedGraph to calculate the axis ranges
            z1.AxisChange();
            z1.Invalidate();
        }
Exemplo n.º 6
0
        // Call this method from the Form_Load method, passing your ZedGraphControl
        public void CreateGraph_JapaneseCandleStickDemo( ZedGraphControl zgc )
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "Japanese Candlestick Chart Demo";
            myPane.XAxis.Title.Text = "Trading Date";
            myPane.YAxis.Title.Text = "Share Price, $US";

            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;

            for ( int i = 0; i < 50; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );
                spl.Add( pt );

                open = close;
                // Advance one day
                //xDate.AddDays( 1 + 0.4 * rand.NextDouble() - 0.2 );
                xDate.AddDays( 1 );
                // but skip the weekends
                if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                    xDate.AddDays( 2.0 );
            }

            JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl );
            myCurve.Stick.IsAutoSize = true;
            myCurve.Stick.Color = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;
            //myPane.XAxis.Type = AxisType.Date;
            //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 );

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

            // Tell ZedGraph to calculate the axis ranges
            zgc.AxisChange();
            zgc.Invalidate();
        }
Exemplo n.º 7
0
        public void CreateGraph_SortedOverlayBars2( ZedGraphControl zgc )
        {
            GraphPane myPane = zgc.GraphPane;
            const int count = 52;
            PointPairList ppl1 = new PointPairList();
            PointPairList ppl2 = new PointPairList();
            PointPairList ppl3 = new PointPairList();
            double val1 = 50.0;
            double val2 = 50.0;
            double val3 = 50.0;
            Random rand = new Random();
            XDate xDate = new XDate( 2005, 1, 1 );
            for ( int i = 0; i < count; i++ )
            {
                //double x = i + 1;
                val1 += rand.NextDouble() * 10.0 - 5.0;
                val2 += rand.NextDouble() * 10.0 - 5.0;
                val3 += rand.NextDouble() * 10.0 - 5.0;

                if ( i == 30 )
                    xDate.AddDays( 7 );

                //double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                //double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;
                ppl1.Add( xDate, val1 );
                ppl2.Add( xDate, val2 );
                ppl3.Add( xDate, val3 );

                xDate.AddDays( 7 );
            }
            // Generate a red bar with "Curve 1" in the legend
            CurveItem myCurve = myPane.AddBar( "Curve 1", ppl1, Color.Red );
            // Generate a blue bar with "Curve 2" in the legend
            myCurve = myPane.AddBar( "Curve 2", ppl2, Color.Blue );
            // Generate a green bar with "Curve 3" in the legend
            myCurve = myPane.AddBar( "Curve 3", ppl3, Color.Green );
            //myPane.XAxis.Type = AxisType.DateAsOrdinal;
            myPane.XAxis.Type = AxisType.Date;
            // Make the bars a sorted overlay type so that they are drawn on top of eachother
            // (without summing), and each stack is sorted so the shorter bars are in front
            // of the taller bars
            myPane.BarSettings.Type = BarType.SortedOverlay;
            // Fill the axis background with a color gradient
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0F );
            // Calculate the Axis Scale Ranges
            zgc.AxisChange();
        }
Exemplo n.º 8
0
        // Make a masterpane with 3 charts
        // Top = OHLC Bar Chart
        // Mid = Volume Chart
        // Bot = Price Change
        public void CreateGraph_OHLCBarMaster( ZedGraphControl zgc )
        {
            // ================================================
            // First, set up some lists with random data...
            // ================================================
            StockPointList spl = new StockPointList();
            PointPairList volList = new PointPairList();
            PointPairList changeList = new PointPairList();

            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;
            double prevClose = 50.0;
            const int numDays = 365;

            // Loop to make 365 days of data
            for ( int i = 0; i < numDays; i++ )
            {
                double x = xDate.XLDate;
                //double close = open + rand.NextDouble() * 10.0 - 5.0;
                double close = open * ( 0.95 + rand.NextDouble() * 0.1 );
                //double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                //double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;
                double hi = Math.Max( open, close ) * ( 1.0 + rand.NextDouble() * 0.05 );
                double low = Math.Min( open, close ) * ( 0.95 + rand.NextDouble() * 0.05 );
                double vol = 25.0 + rand.NextDouble() * 100.0;
                double change = close - prevClose;

                // Create a StockPt instead of a PointPair so we can carry 6 properties
                StockPt pt = new StockPt( x, hi, low, open, close, vol );

                //if price is increasing color=black, else color=red
                pt.ColorValue = close > prevClose ? 2 : 1;
                spl.Add( pt );

                volList.Add( x, vol );
                changeList.Add( x, change );

                prevClose = close;
                open = close;
                // Advance one day
                xDate.AddDays( 1.0 );
                // but skip the weekends
                if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                    xDate.AddDays( 2.0 );
            }

            // ================================================
            // Create 3 GraphPanes to display the data
            // ================================================

            // get a reference to the masterpane
            MasterPane master = zgc.MasterPane;

            // The first chart is already in the MasterPane, so add the other two charts
            master.Add( new GraphPane() );
            master.Add( new GraphPane() );

            // ================================================
            // The first pane is an OHLCBarItem
            // ================================================

            // Get a reference to the pane
            GraphPane pane = master[0];

            // Set the title and axis labels
            pane.Title.Text = "Open-High-Low-Close History";
            pane.XAxis.Title.Text = "Date";
            pane.YAxis.Title.Text = "Price";

            // Setup the gradient fill...
            // Use Red for negative days and black for positive days
            Color[] colors = { Color.Red, Color.Black };
            Fill myFill = new Fill( colors );
            myFill.Type = FillType.GradientByColorValue;
            myFill.SecondaryValueGradientColor = Color.Empty;
            myFill.RangeMin = 1;
            myFill.RangeMax = 2;

            //Create the OHLC and assign it a Fill
            OHLCBarItem ohlcCurve = pane.AddOHLCBar( "Price", spl, Color.Empty );
            ohlcCurve.Bar.GradientFill = myFill;
            ohlcCurve.Bar.IsAutoSize = true;
            // Create a JapaneseCandleStick
            //JapaneseCandleStickItem jcsCurve = pane.AddJapaneseCandleStick( "Price", spl );
            //jcsCurve.Stick.IsAutoSize = false;

            // ================================================
            // The second pane is a regular BarItem to show daily volume
            // ================================================

            // Get a reference to the pane
            pane = master[1];

            // Set the title and axis labels
            pane.Title.Text = "Daily Volume";
            pane.XAxis.Title.Text = "Date";
            pane.YAxis.Title.Text = "Volume, thousands";

            BarItem volBar = pane.AddBar( "Volume", volList, Color.Blue );

            // ================================================
            // The third pane is a LineItem to show daily price change
            // ================================================

            // Get a reference to the pane
            pane = master[2];

            // Set the title and axis labels
            pane.Title.Text = "Price Change";
            pane.XAxis.Title.Text = "Date";
            pane.YAxis.Title.Text = "Price Change, $";

            LineItem changeCurve = pane.AddCurve( "Price Change", changeList, Color.Green, SymbolType.None );

            // ================================================
            // These settings are common to all three panes
            // ================================================

            foreach ( GraphPane paneT in master.PaneList )
            {
                // Use DateAsOrdinal to skip weekend gaps
                paneT.XAxis.Type = AxisType.DateAsOrdinal;
                // Use only visible data to define Y scale range
                paneT.IsBoundedRanges = true;
                // Define a minimum buffer space to the axes can be aligned
                paneT.YAxis.MinSpace = 80;
                paneT.Y2Axis.MinSpace = 50;

                // pretty it up a little
                paneT.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
                paneT.Title.FontSpec.Size = 20.0f;
                paneT.XAxis.Title.FontSpec.Size = 18.0f;
                paneT.XAxis.Scale.FontSpec.Size = 16.0f;
                paneT.YAxis.Title.FontSpec.Size = 18.0f;
                paneT.YAxis.Scale.FontSpec.Size = 16.0f;
                paneT.Legend.IsVisible = false;
                paneT.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );

                // Set the initial scroll position and range
                // Note that the min and max for DateAsOrdinal scale will be ordinal values, not dates
                paneT.XAxis.Scale.Min = 1.0;
                // default range is 30 days
                paneT.XAxis.Scale.Max = 30.0;

            }

            // ================================================
            // Set up the MasterPane Layout
            // ================================================

            // Make sure that fonts and dimensions are the same for all three charts
            master.IsCommonScaleFactor = true;

            // Show the masterpane title
            master.Title.IsVisible = true;
            master.Title.Text = "Wacky Widget Company Stock Performance";
            master.Fill = new Fill( Color.White, Color.SlateBlue, 45.0f );

            // Leave a margin around the masterpane, but only a small gap between panes
            master.Margin.All = 10;
            master.InnerPaneGap = 5;

            using ( Graphics g = this.CreateGraphics() )
            {

                master.SetLayout( g, PaneLayout.SingleColumn );

                // Synchronize the Axes
                zgc.IsAutoScrollRange = true;
                zgc.IsShowHScrollBar = true;
                zgc.IsSynchronizeXAxes = true;
                // Scale range will extend about 1 day before and after the actual data range
                zgc.ScrollGrace = 1.0 / numDays;
            }

            // Tell ZedGraph to calculate the axis ranges
            zgc.AxisChange();

            //			master[0].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate;
            //			master[0].XAxis.Scale.Max = master[0].XAxis.Scale.Min + 30.0;
            //			master[1].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate;
            //			master[1].XAxis.Scale.Max = master[1].XAxis.Scale.Min + 30.0;
            //			master[2].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate;
            //			master[2].XAxis.Scale.Max = master[2].XAxis.Scale.Min + 30.0;

            //zgc.ScrollDoneEvent += new ZedGraphControl.ScrollDoneHandler( zgc_ScrollDoneEvent );
            zgc.ScrollProgressEvent += new ZedGraphControl.ScrollProgressHandler( zgc_ScrollProgressEvent );
        }
Exemplo n.º 9
0
        public void CreateGraph_OHLCBarGradient( ZedGraphControl zgc )
        {
            GraphPane myPane = zgc.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = "OHLC Chart Demo";
            myPane.XAxis.Title.Text = "Date";
            myPane.YAxis.Title.Text = "Price";

            //Load a StockPointList with random data.........................
            StockPointList spl = new StockPointList();
            Random rand = new Random();

            // First day is jan 1st
            XDate xDate = new XDate( 2006, 1, 1 );
            double open = 50.0;
            double prevClose = 0;

            // Loop to make 50 days of data
            for ( int i = 0; i < 50; i++ )
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0;
                double low = Math.Min( open, close ) - rand.NextDouble() * 5.0;

                // Create a StockPt instead of a PointPair so we can carry 6 properties
                StockPt pt = new StockPt( x, hi, low, open, close, 100000 );

                //if price is increasing color=black, else color=red
                pt.ColorValue = close > prevClose ? 2 : 1;
                spl.Add( pt );

                prevClose = close;
                open = close;
                // Advance one day
                xDate.AddDays( 1.0 );
                // but skip the weekends
                if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 )
                    xDate.AddDays( 2.0 );
            }

            // Setup the gradient fill...
            // Use Red for negative days and black for positive days
            Color[] colors = { Color.Red, Color.Black };
            Fill myFill = new Fill( colors );
            myFill.Type = FillType.GradientByColorValue;
            myFill.SecondaryValueGradientColor = Color.Empty;
            myFill.RangeMin = 1;
            myFill.RangeMax = 2;

            //Create the OHLC and assign it a Fill
            OHLCBarItem myCurve = myPane.AddOHLCBar( "Price", spl, Color.Empty );
            myCurve.Bar.GradientFill = myFill;
            myCurve.Bar.IsAutoSize = true;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;
            //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 );

            // pretty it up a little
            myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f );
            myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f );
            myPane.Title.FontSpec.Size = 20.0f;
            myPane.XAxis.Title.FontSpec.Size = 18.0f;
            myPane.XAxis.Scale.FontSpec.Size = 16.0f;
            myPane.YAxis.Title.FontSpec.Size = 18.0f;
            myPane.YAxis.Scale.FontSpec.Size = 16.0f;
            myPane.Legend.IsVisible = false;

            //			BoxObj box = new BoxObj( 4.5, 0.0, 1.0, 1.0, Color.Transparent,
            //					Color.FromArgb( 100, Color.LightBlue ) );
            //			box.Location.CoordinateFrame = CoordType.XScaleYChartFraction;
            //			myPane.GraphObjList.Add( box );

            // Tell ZedGraph to calculate the axis ranges
            zgc.AxisChange();
            zgc.Invalidate();
        }
Exemplo n.º 10
0
		/// <summary>
		/// Determine the value for any minor tic.
		/// </summary>
		/// <remarks>
		/// This method properly accounts for <see cref="Scale.IsLog"/>, <see cref="Scale.IsText"/>,
		/// and other axis format settings.
		/// </remarks>
		/// <param name="baseVal">
		/// The value of the first major tic (floating point double).  This tic value is the base
		/// reference for all tics (including minor ones).
		/// </param>
		/// <param name="iTic">
		/// The major tic number (0 = first major tic).  For log scales, this is the actual power of 10.
		/// </param>
		/// <returns>
		/// The specified minor tic value (floating point double).
		/// </returns>
		internal override double CalcMinorTicValue(double baseVal, int iTic)
		{
			XDate xDate = new XDate(baseVal);

			switch (_minorUnit) {
				case DateUnit.Year:
				default:
					xDate.AddYears((double) iTic*_minorStep);
					break;
				case DateUnit.Month:
					xDate.AddMonths((double) iTic*_minorStep);
					break;
				case DateUnit.Day:
					xDate.AddDays((double) iTic*_minorStep);
					break;
				case DateUnit.Hour:
					xDate.AddHours((double) iTic*_minorStep);
					break;
				case DateUnit.Minute:
					xDate.AddMinutes((double) iTic*_minorStep);
					break;
				case DateUnit.Second:
					xDate.AddSeconds((double) iTic*_minorStep);
					break;
			}

			return xDate.XLDate;
		}
Exemplo n.º 11
0
        /// <summary>
        /// Draws the statistics.
        /// </summary>
        /// <remarks>Documented by Dev05, 2007-08-28</remarks>
        public void DrawStatistics()
        {
            if (loading)
                return;

            # region set values and start time/date
            int values;
            XDate date = new XDate(DateTime.Now);
            TimeSpan offset = new TimeSpan(1, 0, 0, 0);
            AxisType axisType = AxisType.Text;

            switch ((TimeFrame)CBShow.SelectedIndex)
            {
                case TimeFrame.Today:
                    values = date.DateTime.Hour;
                    //date.DateTime = date.DateTime.AddHours(-date.DateTime.Hour);
                    //date.DateTime = date.DateTime.AddMinutes(-date.DateTime.Minute);
                    //date.DateTime = date.DateTime.AddSeconds(-date.DateTime.Second);
                    date.DateTime = date.DateTime.Date;
                    offset = new TimeSpan(1, 0, 0);
                    axisType = AxisType.Date;
                    break;
                case TimeFrame.Week:
                    values = 7;
                    date.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59).AddDays(-7);
                    break;
                case TimeFrame.Month:
                    values = 30;
                    date.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59).AddDays(-30);
                    break;
                case TimeFrame.Year:
                    values = 12;
                    date.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59).AddDays(-365);
                    offset = new TimeSpan(31, 0, 0, 0);
                    break;
                case TimeFrame.All:
                default:
                    values = (Dictionary.Statistics.GetNewestStatistic().EndTimestamp -
                        Dictionary.Statistics.GetOldestStatistic().EndTimestamp).Days + 1;
                    date.DateTime = Dictionary.Statistics.GetOldestStatistic().EndTimestamp;
                    break;
            }
            values++;
            # endregion
            # region initialize graphs

            //for performance
            int activeCards = Dictionary.Cards.ActiveCardsCount;

            GraphPane knowledgePane = zedGraphControlKnowledge.GraphPane;
            GraphPane distrubutionPane = zedGraphControlMemoryDistribution.GraphPane;
            GraphPane currentPane = zedGraphControlCurrentDistribution.GraphPane;

            knowledgePane.CurveList.Clear();
            distrubutionPane.CurveList.Clear();
            currentPane.CurveList.Clear();

            knowledgePane.Title.Text = Properties.Resources.STATISTICS_KNOWLEDGE_CAPTION;
            knowledgePane.XAxis.Title.Text = Properties.Resources.STATISTICS_XAXIS;
            knowledgePane.YAxis.Title.Text = Properties.Resources.STATISTICS_YAXIS;
            distrubutionPane.Title.Text = Properties.Resources.STATISTICS_DISTRIBUTION_CAPTION;
            distrubutionPane.XAxis.Title.Text = Properties.Resources.STATISTICS_XAXIS;
            distrubutionPane.YAxis.Title.Text = Properties.Resources.STATISTICS_YAXIS;
            currentPane.Title.Text = Properties.Resources.STATISTICS_OTHER;
            currentPane.Title.FontSpec.Size = 24;
            currentPane.Title.FontSpec.IsBold = true;

            knowledgePane.YAxis.Scale.Max = activeCards + 1;
            knowledgePane.YAxis.Scale.Min = 0;
            distrubutionPane.YAxis.Scale.Max = 10;
            //distrubutionPane.YAxis.Scale.MinorStep = 1;
            distrubutionPane.YAxis.Scale.Min = 0;

            if (((TimeFrame)CBShow.SelectedIndex) == TimeFrame.Today)
            {
                knowledgePane.XAxis.Scale.Min = (new XDate(date.DateTime + offset)).XLDate;
                knowledgePane.XAxis.Scale.Max = (new XDate(DateTime.Now + offset)).XLDate;
                distrubutionPane.XAxis.Scale.Min = (new XDate(date.DateTime + offset)).XLDate;
                distrubutionPane.XAxis.Scale.Max = (new XDate(DateTime.Now + offset)).XLDate;
            }
            else
            {
                knowledgePane.XAxis.Scale.Min = 2;
                knowledgePane.XAxis.Scale.Max = values + 2;
                distrubutionPane.XAxis.Scale.Min = 1;
                distrubutionPane.XAxis.Scale.Max = values + 1;
            }

            knowledgePane.XAxis.Type = axisType;

            distrubutionPane.XAxis.Type = axisType;
            distrubutionPane.BarSettings.Type = BarType.Stack;
            distrubutionPane.Legend.Position = LegendPos.Right;
            distrubutionPane.Legend.Gap = 0;

            currentPane.Legend.IsVisible = false;
            currentPane.Legend.Position = LegendPos.Right;
            currentPane.Legend.Gap = 0;
            currentPane.Legend.FontSpec.Size = 18;

            knowledgePane.Fill = new Fill(Color.WhiteSmoke, Color.Lavender, 0F);
            knowledgePane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245),
                Color.FromArgb(255, 255, 190), 90F);
            distrubutionPane.Fill = new Fill(Color.WhiteSmoke, Color.Lavender, 0F);
            distrubutionPane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245),
                Color.FromArgb(255, 255, 190), 90F);

            List<string> xAxisListKnowledge = new List<string>();
            List<string> xAxisListDistribution = new List<string>();

            //Add "filler labels" for the x axis to correspond properly to the values
            date.AddDays(-1);
            AddCurrentPointLabel(ref xAxisListKnowledge, date);
            if (((TimeFrame)CBShow.SelectedIndex) == TimeFrame.All)
            {
                AddCurrentPointLabel(ref xAxisListKnowledge, date);
                AddCurrentPointLabel(ref xAxisListDistribution, date);
            }
            date.AddDays(1);

            PointPairList targetList = new PointPairList();
            targetList.Add(new PointPair(0, activeCards));
            PointPairList knownList = new PointPairList();

            PointPairList[] boxLists = new PointPairList[10];
            for (int k = 0; k < boxLists.Length; k++)
                boxLists[k] = new PointPairList();
            # endregion
            # region get values
            knownList.Add(new PointPair(0, Dictionary.Statistics.GetKnown(date.DateTime)));

            while (date.DateTime <= DateTime.Now + offset)
            {
                targetList.Add(new PointPair(date.XLDate, activeCards));
                int known = Dictionary.Statistics.GetKnown(date.DateTime);
                knownList.Add(new PointPair(date.XLDate, known));

                int box1 = Dictionary.Statistics.GetBoxContent(1, date.DateTime);
                boxLists[0].Add(new PointPair(date.XLDate, box1));
                for (int i = 2; i <= 10; i++)
                    boxLists[i - 1].Add(new PointPair(date.XLDate, Dictionary.Statistics.GetBoxContent(i, date.DateTime)));

                if (known + box1 + 1 > distrubutionPane.YAxis.Scale.Max)
                    distrubutionPane.YAxis.Scale.Max = known + box1 + 1;

                AddCurrentPointLabel(ref xAxisListKnowledge, date);
                AddCurrentPointLabel(ref xAxisListDistribution, date);

                date.DateTime += offset;
            }

            CheckDoubleDistribution(ref boxLists);

            knowledgePane.XAxis.Scale.TextLabels = xAxisListKnowledge.ToArray();
            distrubutionPane.XAxis.Scale.TextLabels = xAxisListDistribution.ToArray();

            targetList.Add(new PointPair(date.XLDate + 1, activeCards));
            knownList.Add(new PointPair(date.XLDate + 1, knownList[knownList.Count - 1].Y));

            # endregion
            # region draw lines
            if (checkBoxShowTarget.Checked)
            {
                LineItem targetLine = knowledgePane.AddCurve(Resources.STATISTICS_KNOWLEDGE_TAB_TARGET_CARDS_STRING, targetList, Color.Red, SymbolType.None);
                targetLine.Line.Width = 2;
                targetLine.Line.IsSmooth = true;
                targetLine.Line.SmoothTension = 1;
            }
            else
            {
                double max = -1;
                foreach (PointPair pp in knownList)
                    if (pp.Y > max)
                        max = pp.Y;
                knowledgePane.YAxis.Scale.Max = max + 1;
            }

            LineItem knownLine = knowledgePane.AddCurve(Resources.STATISTICS_KNOWLEDGE_TAB_KNOWN_CARDS_STRING, knownList, Color.Blue, SymbolType.None);
            knownLine.Line.Width = 2;
            knownLine.Line.Fill = new Fill(Color.WhiteSmoke, Color.LightBlue, Color.DodgerBlue);
            knownLine.Line.IsAntiAlias = true;

            for (int k = 0; k < boxLists.Length; k++)
            {
                CurveItem boxLine = distrubutionPane.AddBar(String.Format(Resources.STATISTICS_KNOWLEDGE_TAB_BOX_STRING, (k + 1).ToString()), boxLists[k], GradientColors[k]);
            }

            for (int k = 1; k < Dictionary.Boxes.Count; k++)
            {
                PieItem item = currentPane.AddPieSlice(Dictionary.Boxes[k].Size, GradientColors[k], 0,
                    String.Format(Resources.STATISTICS_OTHER_TAB_BOX_SIZE_STRING, k, Dictionary.Boxes[k].Size));
                item.LabelDetail.FontSpec.Size = 16;
                item.Fill = new Fill(Color.WhiteSmoke, GradientColors[k], 45F);

                if (Dictionary.Boxes[k].Size <= 0)
                    item.LabelDetail.IsVisible = false;
            }

            PieItem poolItem = currentPane.AddPieSlice(Dictionary.Boxes[0].Size, GradientColors[0], 0,
                String.Format(Resources.STATISTICS_OTHER_TAB_POOL_SIZE_STRING, Dictionary.Boxes[0].Size));
            poolItem.LabelDetail.FontSpec.Size = 16;
            poolItem.Fill = new Fill(Color.WhiteSmoke, GradientColors[0], 45F);

            if (Dictionary.Boxes[0].Size <= 0)
                poolItem.LabelDetail.IsVisible = false;

            # endregion
            zedGraphControlKnowledge.AxisChange();
            zedGraphControlKnowledge.Refresh();
            zedGraphControlMemoryDistribution.AxisChange();
            zedGraphControlMemoryDistribution.Refresh();
            zedGraphControlCurrentDistribution.AxisChange();
            zedGraphControlCurrentDistribution.Refresh();
        }
Exemplo n.º 12
0
        private static StockPointList CreateStockPointList(long valueStepSizeMinutes)
        {
            StockPointList spl = new StockPointList();
            Random rand = new Random();

            XDate xDate = new XDate(2013, 1, 1);
            double open = 50.0;

            for (int i = 0; i < 50; i++)
            {
                double x = xDate.XLDate;
                double close = open + rand.NextDouble() * 10.0 - 5.0;
                double hi = Math.Max(open, close) + rand.NextDouble() * 5.0;
                double low = Math.Min(open, close) - rand.NextDouble() * 5.0;

                StockPt pt = new StockPt(x, hi, low, open, close, 100000);
                spl.Add(pt);

                open = close;
                xDate.AddMinutes(valueStepSizeMinutes);

                if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
                {
                    xDate.AddDays(2.0);
                }
            }

            return spl;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Determine the value for any minor tic.
        /// </summary>
        /// <remarks>
        /// This method properly accounts for <see cref="IsLog"/>, <see cref="IsText"/>,
        /// and other axis format settings.
        /// </remarks>
        /// <param name="baseVal">
        /// The value of the first major tic (floating point double).  This tic value is the base
        /// reference for all tics (including minor ones).
        /// </param>
        /// <param name="iTic">
        /// The major tic number (0 = first major tic).  For log scales, this is the actual power of 10.
        /// </param>
        /// <returns>
        /// The specified minor tic value (floating point double).
        /// </returns>
        private double CalcMinorTicValue( double baseVal, int iTic )
        {
            double[] dLogVal = { 0, 0.301029995663981, 0.477121254719662, 0.602059991327962,
                                    0.698970004336019, 0.778151250383644, 0.845098040014257,
                                    0.903089986991944, 0.954242509439325, 1 };

            if ( this.IsDate ) // date scale
            {
                XDate xDate= new XDate( baseVal );

                switch ( this.minorUnit )
                {
                    case DateUnit.Year:
                    default:
                        xDate.AddYears( (double) iTic * this.minorStep );
                        break;
                    case DateUnit.Month:
                        xDate.AddMonths( (double) iTic * this.minorStep );
                        break;
                    case DateUnit.Day:
                        xDate.AddDays( (double) iTic * this.minorStep );
                        break;
                    case DateUnit.Hour:
                        xDate.AddHours( (double) iTic * this.minorStep );
                        break;
                    case DateUnit.Minute:
                        xDate.AddMinutes( (double) iTic * this.minorStep );
                        break;
                    case DateUnit.Second:
                        xDate.AddSeconds( (double) iTic * this.minorStep );
                        break;
                }

                return xDate.XLDate;
            }
            else if ( this.IsLog ) // log scale
            {
                return baseVal + Math.Floor( (double) iTic / 9.0 ) + dLogVal[ ( iTic + 9 ) % 9 ];
            }
            else // regular linear scale
            {
                return baseVal + (double) this.minorStep * (double) iTic;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Determine the value for any major tic.
        /// </summary>
        /// <remarks>
        /// This method properly accounts for <see cref="IsLog"/>, <see cref="IsText"/>,
        /// and other axis format settings.
        /// </remarks>
        /// <param name="baseVal">
        /// The value of the first major tic (floating point double)
        /// </param>
        /// <param name="tic">
        /// The major tic number (0 = first major tic).  For log scales, this is the actual power of 10.
        /// </param>
        /// <returns>
        /// The specified major tic value (floating point double).
        /// </returns>
        private double CalcMajorTicValue( double baseVal, double tic )
        {
            if ( this.IsDate ) // date scale
            {
                XDate xDate = new XDate( baseVal );

                switch ( this.majorUnit )
                {
                    case DateUnit.Year:
                    default:
                        xDate.AddYears( tic * this.step );
                        break;
                    case DateUnit.Month:
                        xDate.AddMonths( tic * this.step );
                        break;
                    case DateUnit.Day:
                        xDate.AddDays( tic * this.step );
                        break;
                    case DateUnit.Hour:
                        xDate.AddHours( tic * this.step );
                        break;
                    case DateUnit.Minute:
                        xDate.AddMinutes( tic * this.step );
                        break;
                    case DateUnit.Second:
                        xDate.AddSeconds( tic * this.step );
                        break;
                }

                return xDate.XLDate;
            }
            else if ( this.IsLog ) // log scale
            {
                return baseVal + (double) tic;
            }
            else // regular linear scale
            {
                return baseVal + (double) this.step * tic;
            }
        }