ASP.NET + C#  画趋势图,每个月一个节点,且每个节点可以点击查询相应的数据,请问各位大侠该怎么做?如果背景颜色能随纵坐标由绿变红渐变就更好了.小弟先谢过各位了。急。。

解决方案 »

  1.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Drawing;
    using System.Drawing.Imaging;
    public partial class Default5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Pic();
        }
        private void Pic()
        {
            //测试数据
            DataTable table = new DataTable("Data");
            DataRow Dr;
            DataColumn Dc = new DataColumn("ID",Type.GetType("System.Int32"));
            DataColumn Dc2 = new DataColumn("Num",Type.GetType("System.Int32"));
            DataColumn Dc3 = new DataColumn("name", Type.GetType("System.String"));
            table.Columns.Add(Dc);
            table.Columns.Add(Dc2);
            table.Columns.Add(Dc3);
            Random rnd=new Random();
            for (int n = 0; n < 61; n++)
            {
                Dr = table.NewRow();
                Dr[0] = n;
                Dr[1] = rnd.Next(10, 140);
                Dr[2] = n.ToString();
                table.Rows.Add(Dr);
            }
            //画图参数
            int BG_Width = 450;
            int BG_Height = 180;
            int Pic_Width = 450;
            int Pic_Height = 180;
            int pic_X = 6;
            int pic_H = 1;
            int pic_tr=5;
            int pic_td = 12;
            Rectangle rec = new Rectangle(50, 15, 360, 150);
            Pen Pic_Bolder = new Pen(Color.Black, 1);
            Pen Pic_line = new Pen(Color.Gray, 1);
            Pen Pic_Data = new Pen(Color.Red,2);
            SolidBrush brusth = new SolidBrush(Color.Blue);
            Point[] DataPt = new Point[table.Rows.Count];
            int x;
            int y;
            for (int n = 0; n < table.Rows.Count; n++)
            {
                Dr=table.Rows[n];
                x=(int)Dr[0] * pic_X + rec.X;
                y=(int)Dr[1] * pic_H + rec.Y;
                DataPt[n] = new Point(x,y);
            }
            Bitmap Bg = new Bitmap(BG_Width, BG_Height, PixelFormat.Format24bppRgb);
            Graphics Ph = Graphics.FromImage(Bg);
            Ph.Clear(Color.White);       
            Ph.DrawRectangle(Pic_Bolder, rec);
            //画折线
            Ph.DrawCurve(Pic_Data, DataPt);
            //rec.
            Point SPoint=new Point();
            Point Epoint=new Point();
            //画横线
            for (int n = 1; n < pic_tr; n++)
            {
               //cell[0] = new Point(rec.X);
                SPoint.X = 0 + rec.X;
                SPoint.Y = n * 30 + rec.Y;
                Epoint.X = rec.Width + rec.X;
                Epoint.Y = n * 30 + rec.Y;
                Ph.DrawLine(Pic_line,SPoint,Epoint);
            }
            //画竖线
            for (int n = 1; n < pic_td; n++)
            {
                SPoint.X = n * 30 +rec.X;
                SPoint.Y = rec.Y;
                Epoint.X = n * 30 + rec.X;
                Epoint.Y = rec.Height+ rec.Y;
                Ph.DrawLine(Pic_line, SPoint, Epoint);
            }
            //画标题
            string Title = "画折线测试";        
            SolidBrush brush=new SolidBrush(Color.RoyalBlue);
            Ph.DrawString(Title, new Font("Franklin Gothic Demi", 12, FontStyle.Italic), brush, new Point(200, 0));
            Ph.Save();
            Bg.Save(Response.OutputStream, ImageFormat.Gif);
        }
    }
      

  2.   

    http://download.csdn.net/down/418908/cumttoneu
      

  3.   

    to zzxap,先谢过高手。还有一个重要的问题就是趋势图上的每一个节点要可以点击(从数据库查询相应的数据),比如1到12月每月有一个节点,每个月的节点连接起来构成一个趋势线,当点击某个节点时查询相应月的数据,请问怎样才能做到节点可以点击,能给帮我想一下解决方案吗,非常感谢!
      

  4.   

    http://aspspider.ws/Chartlet/Demo.aspx 
     这里有个图表控件 ..
      

  5.   

     那要画热区显示
    用owc,zedgraph都可显示或FLASH编写代码实现连接
    参考
    参考
      

  6.   

    FusionChartsFree
    CSDN也有下载:
    http://search.download.csdn.net/search/FusionChartsFree