예제 #1
0
        private async void populateGraph()
        {
            List <String> symbolList = new List <string>();
            PointPairList list1      = new PointPairList();
            PointPairList list2      = new PointPairList();
            PointPairList list3      = new PointPairList();
            PointPairList list4      = new PointPairList();
            PointPairList list5      = new PointPairList();


            LineItem curve1 = new LineItem("curve1");
            LineItem curve2 = new LineItem("curve1");
            LineItem curve3 = new LineItem("curve1");
            LineItem curve4 = new LineItem("curve1");
            LineItem curve5 = new LineItem("curve1");


            List <Color> colorList = new List <Color>()
            {
                Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Pink
            };
            List <PointPairList> pointpairList = new List <PointPairList>()
            {
                list1, list2, list3, list4, list5
            };
            List <LineItem> lineItem = new List <LineItem>()
            {
                curve1, curve2, curve3, curve4, curve5
            };



            foreach (DataGridViewRow item in watchlistDataGridView.Rows)
            {
                symbolList.Add(item.Cells["Symbol"].Value.ToString());
            }

            double x = 0;
            // double y = 0 ;
            List <double> y = new List <double>()
            {
                0.0, 0.0, 0.0, 0.0, 0.0
            };


            zg1.GraphPane.CurveList.Clear();
            zg1.GraphPane.GraphObjList.Clear();
            // Get a reference to the GraphPane instance in the ZedGraphControl
            GraphPane myPane = zg1.GraphPane;

            // Set the titles and axis labels
            //myPane.Title.Text = "Historical Graph of " + name;
            myPane.XAxis.Title.Text = "Time, Days";
            myPane.YAxis.Title.Text = "Daily Close Value";



            //loadingCircle.Visible = true;

            for (int i = 0; i < symbolList.Count; i++)
            {
                //MessageBox.Show(symbolList[i]);


                // Make up some data points based on the Sine function
                // PointPairList list = new PointPairList();
                //pointpairList[i] = new PointPairList();
                List <HistoricalStock> data = await Task.Run(() => HistoricalStockDownloader.DownloadData(symbolList[i], DateTime.Now.Year));

                //List<HistoricalStock> data = HistoricalStockDownloader.DownloadData(symbolList[i], DateTime.Now.Year);
                //MessageBox.Show((DateTime.Now.Year - 5).ToString());



                foreach (var j in data)
                {
                    if (j.Date.Year >= (DateTime.Now.Year))
                    {
                        x    = (double)new XDate(j.Date);
                        y[i] = j.Close;
                        pointpairList[i].Add(x, y[i]);
                    }
                }


                //pointpairList[i].Add(x, y[i]);
                // loadingCircle.Visible = false;
                // Generate a red curve

                //LineItem myCurve = myPane.AddCurve(symbolList[i],
                //    pointpairList[i], colorList[i], SymbolType.None);


                lineItem[i] = myPane.AddCurve(symbolList[i],
                                              pointpairList[i], colorList[i], SymbolType.None);

                // Fill the symbols with white
                //myCurve.Symbol.Fill = new Fill(Color.White);


                lineItem[i].Symbol.Fill = new Fill(Color.White);


                // Show the x axis grid
                myPane.XAxis.MajorGrid.IsVisible = true;
                // Set the XAxis to date type
                myPane.XAxis.Type = AxisType.Date;

                // Make the Y axis scale red
                myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
                myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
                // turn off the opposite tics so the Y tics don't show up on the Y2 axis
                //myPane.YAxis.MajorTic.IsOpposite = false;
                //myPane.YAxis.MinorTic.IsOpposite = false;
                // Don't display the Y zero line
                myPane.YAxis.MajorGrid.IsZeroLine = false;
                // Align the Y axis labels so they are flush to the axis
                myPane.YAxis.Scale.Align = AlignP.Inside;


                // Fill the axis background with a gradient
                myPane.Chart.Fill = new Fill(Color.LightYellow, Color.LightGreen, 45.0f);

                //// Add a text box with instructions
                //TextObj text = new TextObj(
                //    "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",
                //    0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
                //text.FontSpec.StringAlignment = StringAlignment.Near;
                //myPane.GraphObjList.Add(text);

                // Enable scrollbars if needed
                zg1.IsShowHScrollBar  = true;
                zg1.IsShowVScrollBar  = true;
                zg1.IsAutoScrollRange = true;
                zg1.IsScrollY2        = true;

                // OPTIONAL: Show tooltips when the mouse hovers over a point
                zg1.IsShowPointValues = true;


                //myPane.YAxis.Scale.Min = 0;
                //myPane.YAxis.Scale.Max = 30;
                //myPane.YAxis.Scale.MajorStep = 1;

                myPane.XAxis.Scale.Format    = "yyyy";
                myPane.XAxis.Scale.MajorUnit = DateUnit.Year;
                myPane.XAxis.Scale.MinorUnit = DateUnit.Year;
                // myPane.XAxis.Scale.Min = new XDate(DateTime.Now.Year - 5.0);
                //myPane.XAxis.Scale.Max = new XDate(DateTime.Now.Year + 0.0);


                // Tell ZedGraph to calculate the axis ranges
                // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
                // up the proper scrolling parameters
                zg1.AxisChange();
                // Make sure the Graph gets redrawn
                zg1.Invalidate();
            }
        }
예제 #2
0
        private async void HistoryGraphForm_Load(object sender, EventArgs e)
        {
            // Get a reference to the GraphPane instance in the ZedGraphControl
            GraphPane myPane = zg1.GraphPane;

            //foreach (HistoricalStock stock in data)
            //{
            //    MessageBox.Show(string.Format("Date={0} High={1} Low={2} Open={3} Close{4}", stock.Date, stock.High, stock.Low, stock.Open, stock.Close));
            //}

            // Set the titles and axis labels
            myPane.Title.Text       = "Historical Graph of " + name;
            myPane.XAxis.Title.Text = "Time, Days";
            myPane.YAxis.Title.Text = "Daily Close Value";

            // Make up some data points based on the Sine function
            PointPairList list = new PointPairList();

            loadingCircle.Visible = true;
            List <HistoricalStock> data = await Task.Run(() => HistoricalStockDownloader.DownloadData(symbol, DateTime.Now.Year - 5));

            //MessageBox.Show((DateTime.Now.Year - 5).ToString());

            foreach (var i in data)
            {
                if (i.Date.Year >= (DateTime.Now.Year - 5))
                {
                    double x = (double)new XDate(i.Date);
                    double y = i.Close;
                    list.Add(x, y);
                }
            }
            loadingCircle.Visible = false;
            // Generate a red curve
            LineItem myCurve = myPane.AddCurve(symbol,
                                               list, Color.Red, SymbolType.None);

            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;
            // Set the XAxis to date type
            myPane.XAxis.Type = AxisType.Date;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            //myPane.YAxis.MajorTic.IsOpposite = false;
            //myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;


            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.LightYellow, Color.LightGreen, 45.0f);

            //// Add a text box with instructions
            //TextObj text = new TextObj(
            //    "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse",
            //    0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
            //text.FontSpec.StringAlignment = StringAlignment.Near;
            //myPane.GraphObjList.Add(text);

            // Enable scrollbars if needed
            zg1.IsShowHScrollBar  = true;
            zg1.IsShowVScrollBar  = true;
            zg1.IsAutoScrollRange = true;
            zg1.IsScrollY2        = true;

            // OPTIONAL: Show tooltips when the mouse hovers over a point
            zg1.IsShowPointValues = true;

            // OPTIONAL: Handle the Zoom Event
            zg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent);

            // Size the control to fit the window
            SetSize();

            // Tell ZedGraph to calculate the axis ranges
            // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
            // up the proper scrolling parameters
            zg1.AxisChange();
            // Make sure the Graph gets redrawn
            zg1.Invalidate();
        }
예제 #3
0
        private async void populateGraphControl()
        {
            // Get a reference to the GraphPane instance in the ZedGraphControl
            GraphPane myPane = zg1.GraphPane;

            if (stockDataGridView.SelectedRows.Count <= 0)
            {
                zg1.GraphPane.CurveList.Clear();
                zg1.GraphPane.GraphObjList.Clear();
                // Set the titles and axis labels
                myPane.Title.Text                = "Historical Graph ";
                myPane.XAxis.Title.Text          = "Time, Days";
                myPane.YAxis.Title.Text          = "Daily Close Value";
                myPane.XAxis.MajorGrid.IsVisible = false;

                // Fill the axis background with a gradient
                myPane.Chart.Fill = new Fill(Color.LightYellow, Color.DeepSkyBlue, 45.0f);
                myPane.Fill       = new Fill(Color.LightGreen);
                // Enable scrollbars if needed
                zg1.IsShowHScrollBar  = true;
                zg1.IsShowVScrollBar  = true;
                zg1.IsAutoScrollRange = true;
                zg1.IsScrollY2        = true;
                // OPTIONAL: Show tooltips when the mouse hovers over a point
                zg1.IsShowPointValues = true;
                // Tell ZedGraph to calculate the axis ranges
                // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
                // up the proper scrolling parameters
                zg1.AxisChange();
                // Make sure the Graph gets redrawn
                zg1.Invalidate();
                return;
            }
            String name   = stockDataGridView.SelectedRows[0].Cells["Name"].Value.ToString();
            String symbol = stockDataGridView.SelectedRows[0].Cells["Symbol"].Value.ToString();

            zg1.GraphPane.CurveList.Clear();
            zg1.GraphPane.GraphObjList.Clear();

            // Set the titles and axis labels
            myPane.Title.Text       = "Historical Graph of " + name;
            myPane.XAxis.Title.Text = "Time, Days";
            myPane.YAxis.Title.Text = "Daily Close Value";

            // Make up some data points based on the Sine function
            PointPairList list = new PointPairList();

            this.mainFormLoadingCircle.Visible = true;
            //loadingCircle.Visible = true;
            List <HistoricalStock> data = await Task.Run(() => HistoricalStockDownloader.DownloadData(symbol, DateTime.Now.Year));

            this.mainFormLoadingCircle.Visible = false;

            foreach (var i in data)
            {
                if (i.Date.Year >= (DateTime.Now.Year))
                {
                    double x = (double)new XDate(i.Date);
                    double y = i.Close;
                    list.Add(x, y);
                }
            }
            // loadingCircle.Visible = false;
            // Generate a red curve
            LineItem myCurve = myPane.AddCurve(symbol,
                                               list, Color.Red, SymbolType.None);

            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);

            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;
            // Set the XAxis to date type
            myPane.XAxis.Type = AxisType.Date;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.LightYellow, Color.DeepSkyBlue, 45.0f);
            myPane.Fill       = new Fill(Color.LightGreen);
            // Enable scrollbars if needed
            zg1.IsShowHScrollBar  = true;
            zg1.IsShowVScrollBar  = true;
            zg1.IsAutoScrollRange = true;
            zg1.IsScrollY2        = true;
            // OPTIONAL: Show tooltips when the mouse hovers over a point
            zg1.IsShowPointValues = true;
            // Tell ZedGraph to calculate the axis ranges
            // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets
            // up the proper scrolling parameters
            zg1.AxisChange();
            // Make sure the Graph gets redrawn
            zg1.Invalidate();
        }