예제 #1
0
        /// <summary>
        /// Event that is invoked when user wishes to add another stock
        /// </summary>
        /// <param name="sender">
        /// Button that invokes the event
        /// </param>
        /// <param name="e">
        /// Event Arguments
        /// </param>
        private void addButton_Click(object sender, EventArgs e)
        {
            if (stockTitle.Text == "")
            {
                MessageBox.Show("Please, input a valid stock from the NYSE");
            }
            else
            {
                DateTime       twentyLength = DateTime.Now.Subtract(TimeSpan.FromDays(20));
                StringBuilder  myString     = new StringBuilder();
                WebClientStock webStock     = new WebClientStock();
                Dictionary <DateTime, StockItem> retrievedStockData = new Dictionary <DateTime, StockItem>();
                string index = getIndex(stockTitle.Text);
                d = webStock.getGoogleStock("NYSE", stockTitle.Text, twentyLength, DateTime.Now);


                var series1 = chart.Series.Add(stockTitle.Text + ": " + index);
                var series2 = chart.Series.Add(stockTitle.Text + "Points");
                series2.IsVisibleInLegend = false;
                wDictList.Add(d);
                wStringList.Add(stockTitle.Text);

                foreach (KeyValuePair <DateTime, StockItem> sItem in d)
                {
                    if (button2.Text == "High")
                    {
                        chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getOpenVal());
                        chart.Series[stockTitle.Text + "Points"].Points.AddXY(sItem.Key, sItem.Value.getOpenVal());
                    }
                    else if (button2.Text == "Low")
                    {
                        chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getHighVal());
                        chart.Series[stockTitle.Text + "Points"].Points.AddXY(sItem.Key, sItem.Value.getHighVal());
                    }
                    else if (button2.Text == "Close")
                    {
                        chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getLowVal());
                        chart.Series[stockTitle.Text + "Points"].Points.AddXY(sItem.Key, sItem.Value.getLowVal());
                    }
                    else if (button2.Text == "Volume")
                    {
                        chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getCloseVal());
                        chart.Series[stockTitle.Text + "Points"].Points.AddXY(sItem.Key, sItem.Value.getCloseVal());
                    }
                    else
                    {
                        chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getVolVal());
                        chart.Series[stockTitle.Text + "Points"].Points.AddXY(sItem.Key, sItem.Value.getVolVal());
                    }
                }
                chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
                series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
                series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            }
        }
예제 #2
0
        /// <summary>
        /// Method that extracts the stock data and populates a chart
        /// </summary>
        private void Worker()
        {
            DateTime       twentyLength = DateTime.Now.Subtract(TimeSpan.FromDays(70));
            StringBuilder  myString     = new StringBuilder();
            WebClientStock webStock     = new WebClientStock();
            Dictionary <DateTime, StockItem> retrievedStockData = new Dictionary <DateTime, StockItem>();

            if (stockTitle.Text == "")
            {
                MessageBox.Show("Please, input a New York Stock Exchange (NYSE) Stock.");
            }
            else
            {
                string index = getIndex(stockTitle.Text);
                d = webStock.getGoogleStock("NYSE", stockTitle.Text, twentyLength, DateTime.Now);
                wDictList.Add(d);
                wStringList.Add(stockTitle.Text);
                foreach (KeyValuePair <DateTime, StockItem> sitem in d)
                {
                    Console.WriteLine("Date: {0}", sitem.Key);
                    Console.WriteLine("High Value: {0}", sitem.Value.getHighVal());
                    Console.WriteLine("Low Value: {0}", sitem.Value.getLowVal());
                    Console.WriteLine("Close Value: {0}", sitem.Value.getCloseVal());
                    Console.WriteLine("Volume Value: {0}", sitem.Value.getVolVal());
                    Console.WriteLine("Index Value: {0}", index);
                }

                chart.Series.Clear();
                chart.BackColor = Color.Transparent;
                chart.ChartAreas[0].BackColor = Color.Transparent;
                chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.FromArgb(128, 128, 128);
                chart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.FromArgb(128, 128, 128);
                var series1 = chart.Series.Add(stockTitle.Text + ": " + index);
                var series2 = chart.Series.Add("Points");
                chart.Legends["Legend1"].BackColor = Color.Transparent;
                chart.Legends["Legend1"].ForeColor = Color.FromArgb(128, 128, 128);
                series2.IsVisibleInLegend          = false;

                if (chart.Titles.Count() > 0)
                {
                    chart.Titles.Clear();
                }
                System.Windows.Forms.DataVisualization.Charting.Title t = chart.Titles.Add("Open Values");
                t.ForeColor  = Color.FromArgb(128, 128, 128);
                t.Font       = new System.Drawing.Font("Headline", 12, FontStyle.Bold);
                button2.Text = "High";

                foreach (KeyValuePair <DateTime, StockItem> sItem in d)
                {
                    chart.Series[stockTitle.Text + ": " + index].Points.AddXY(sItem.Key, sItem.Value.getOpenVal());
                    chart.Series["Points"].Points.AddXY(sItem.Key, sItem.Value.getOpenVal());
                }

                chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
                series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
                series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.Width       *= 2;
                RunWCompleted();
                Console.ReadLine();
            }
        }