获取股票的瞬时图C#

来源:互联网 发布:设计软件源码 编辑:程序博客网 时间:2024/06/04 18:06

获取时时线。欢迎转载啊。 

private void getnewpic(string num)        {            try            {                string url = @"http://image2.sinajs.cn/newchart/min/n/sh" + num + ".gif";                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                System.IO.Stream s = request.GetResponse().GetResponseStream();                Image img2 = System.Drawing.Bitmap.FromStream(s);                s.Close();                //生成Bitmap对像                Bitmap img = new Bitmap(img2, 545, 300);                //生成绘图对像                Graphics g = Graphics.FromImage(img);                //定义黑色画笔                Pen Bp = new Pen(Color.Black);                LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);                LinearGradientBrush Transpentbrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Form1.DefaultBackColor, Form1.DefaultBackColor, 1.2F, true);                //string info = " 曲线图生成时间:" + DateTime.Now.ToString();                Font Tfont = new Font("Arial", 9);                //g.DrawString(info, Tfont, Bluebrush, 40, 25);                g.FillRectangle(Transpentbrush, 5, 287, 535, 15);                g.FillRectangle(Transpentbrush, 497, 228, 35, 30);                //保存绘制的图片                MemoryStream stream = new MemoryStream();                img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);                this.pictureBox1.Image = img;            }            catch (Exception ex)            {             }        }

获取日K线。

private void getKpic(string num)        {            try            {                string url = @"http://image2.sinajs.cn/newchart/daily/n/sh" + num + ".gif";                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);                System.IO.Stream s = request.GetResponse().GetResponseStream();                Image img2 = System.Drawing.Bitmap.FromStream(s);                s.Close();                //生成Bitmap对像                Bitmap img = new Bitmap(img2,545, 300);                //生成绘图对像                Graphics g = Graphics.FromImage(img);                //定义黑色画笔                Pen Bp = new Pen(Color.Black);                LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);                LinearGradientBrush Transpentbrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Form1.DefaultBackColor, Form1.DefaultBackColor, 1.2F, true);                //string info = " 曲线图生成时间:" + DateTime.Now.ToString();                Font Tfont = new Font("Arial", 9);                //g.DrawString(info, Tfont, Bluebrush, 40, 25);                g.FillRectangle(Transpentbrush, 5, 287, 535, 15);                //保存绘制的图片                MemoryStream stream = new MemoryStream();                img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);                this.pictureBox1.Image = img;            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }        }
原创粉丝点击