예제 #1
0
        private void Form2_Load(object sender, EventArgs e)
        {
            DrawM();
            int height = 500;
            int width = 700;
            Bitmap image = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(image);
            Font font = new System.Drawing.Font("宋体",30f);
            Brush brush = Brushes.Red;
            Pen myPen = new Pen(brush, 1);
            //g.FillClosedCurve(Brushes.WhiteSmoke,0,0,);

            //pictureBox1.Image = image;

            return;
            //ChartArea1属性设置
            //设置网格的颜色
            chartHGT.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.LightGray;
            chartHGT.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.LightGray;
            //设置坐标轴名称
            chartHGT.ChartAreas["ChartArea1"].AxisX.Title = "随机数";
            chartHGT.ChartAreas["ChartArea1"].AxisY.Title = "数值";
            //启用3D显示
            chartHGT.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;

            //Series属性设置
            //设置显示类型-线型
            chartHGT.Series["随机数"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            //设置坐标轴Value显示类型
            //chartHGT.Series["随机数"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
            //是否显示标签的数值
            //chartHGT.Series["随机数"].IsValueShownAsLabel = true;
            //设置标记图案
            chartHGT.Series["随机数"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
            //设置图案颜色
            chartHGT.Series["随机数"].Color = Color.Green;
            //设置图案的宽度
            chartHGT.Series["随机数"].BorderWidth = 1;


            ////添加随机数
            //Random rd = new Random();
            //for (int i = 1; i < 20; i++)
            //{
            //    int m = rd.Next(10000);
            //    //chartHGT.Series["随机数"].Points.AddXY(DateTime.Now.Minute + i, rd.Next(10000));
            //    chartHGT.Series["随机数"].Points.AddY(m);
            //    chartHGT.Series["随机数"].Points[i-1].AxisLabel = i.ToString();
            //    chartHGT.Series["随机数"].Points[i - 1].Label = m.ToString();
            //    chartHGT.Series["随机数"].Points[i - 1].ToolTip = m.ToString();

            //}

            List<HGT> listHGT = new List<HGT>();
            string pageContent = ShowHttpWebRequest("http://data.eastmoney.com/bkzj/graph/hgt_1.html");
            if (!string.IsNullOrEmpty(pageContent))
            {
                string[] pageCList = pageContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < pageCList.Length; i++)
                {
                    HGT hgt = new HGT();
                    string[] hgtS = pageCList[i].Split(new char[] { ';' });
                    double hV = 0;
                    double gV = 0;
                    hgt.Data = hgtS[0];
                    if(!string.IsNullOrEmpty(hgtS[1]))
                    {
                        hV = Convert.ToDouble(hgtS[1]);
                        hgt.HValue = hgtS[1];
                    }
                    if (!string.IsNullOrEmpty(hgtS[2]))
                    {
                        gV = Convert.ToDouble(hgtS[2]);
                        hgt.GValue = hgtS[2];
                    }
                    listHGT.Add(hgt);
                    chartHGT.Series["随机数"].Points.AddY(hV);
                    //if(i + 10 >= pageCList.Length)
                    //{
                    chartHGT.Series["随机数"].Points[i].AxisLabel = hgtS[0];
                    //chartHGT.Series["随机数"].Points[i].Label = hV.ToString();
                    //chartHGT.Series["随机数"].Points[i].ToolTip = hV.ToString();
                    chartHGT.Series["随机数"].Points[i].LabelBackColor = Color.Red;
                    //}
                }
            }
            //chartHGT.Series["随机数"].Sort(PointSortOrder.Ascending);
        }
예제 #2
0
        private void Form2_Load(object sender, EventArgs e)
        {
            DrawM();
            int      height = 500;
            int      width  = 700;
            Bitmap   image  = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(image);
            Font     font   = new System.Drawing.Font("宋体", 30f);
            Brush    brush  = Brushes.Red;
            Pen      myPen  = new Pen(brush, 1);

            //g.FillClosedCurve(Brushes.WhiteSmoke,0,0,);

            //pictureBox1.Image = image;

            return;

            //ChartArea1属性设置
            //设置网格的颜色
            chartHGT.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.LightGray;
            chartHGT.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.LightGray;
            //设置坐标轴名称
            chartHGT.ChartAreas["ChartArea1"].AxisX.Title = "随机数";
            chartHGT.ChartAreas["ChartArea1"].AxisY.Title = "数值";
            //启用3D显示
            chartHGT.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;

            //Series属性设置
            //设置显示类型-线型
            chartHGT.Series["随机数"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            //设置坐标轴Value显示类型
            //chartHGT.Series["随机数"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.String;
            //是否显示标签的数值
            //chartHGT.Series["随机数"].IsValueShownAsLabel = true;
            //设置标记图案
            chartHGT.Series["随机数"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
            //设置图案颜色
            chartHGT.Series["随机数"].Color = Color.Green;
            //设置图案的宽度
            chartHGT.Series["随机数"].BorderWidth = 1;


            ////添加随机数
            //Random rd = new Random();
            //for (int i = 1; i < 20; i++)
            //{
            //    int m = rd.Next(10000);
            //    //chartHGT.Series["随机数"].Points.AddXY(DateTime.Now.Minute + i, rd.Next(10000));
            //    chartHGT.Series["随机数"].Points.AddY(m);
            //    chartHGT.Series["随机数"].Points[i-1].AxisLabel = i.ToString();
            //    chartHGT.Series["随机数"].Points[i - 1].Label = m.ToString();
            //    chartHGT.Series["随机数"].Points[i - 1].ToolTip = m.ToString();

            //}

            List <HGT> listHGT     = new List <HGT>();
            string     pageContent = ShowHttpWebRequest("http://data.eastmoney.com/bkzj/graph/hgt_1.html");

            if (!string.IsNullOrEmpty(pageContent))
            {
                string[] pageCList = pageContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < pageCList.Length; i++)
                {
                    HGT      hgt  = new HGT();
                    string[] hgtS = pageCList[i].Split(new char[] { ';' });
                    double   hV   = 0;
                    double   gV   = 0;
                    hgt.Data = hgtS[0];
                    if (!string.IsNullOrEmpty(hgtS[1]))
                    {
                        hV         = Convert.ToDouble(hgtS[1]);
                        hgt.HValue = hgtS[1];
                    }
                    if (!string.IsNullOrEmpty(hgtS[2]))
                    {
                        gV         = Convert.ToDouble(hgtS[2]);
                        hgt.GValue = hgtS[2];
                    }
                    listHGT.Add(hgt);
                    chartHGT.Series["随机数"].Points.AddY(hV);
                    //if(i + 10 >= pageCList.Length)
                    //{
                    chartHGT.Series["随机数"].Points[i].AxisLabel = hgtS[0];
                    //chartHGT.Series["随机数"].Points[i].Label = hV.ToString();
                    //chartHGT.Series["随机数"].Points[i].ToolTip = hV.ToString();
                    chartHGT.Series["随机数"].Points[i].LabelBackColor = Color.Red;
                    //}
                }
            }
            //chartHGT.Series["随机数"].Sort(PointSortOrder.Ascending);
        }