大体要求是从数据库中取出数据,然后生成相应的条形图,饼状图和曲线图,需要用asp.net和C#。本人目前还比较菜,对GDI+的了解还不太多,恳请高手能给我解释下这个绘图生成图片的基本流程,用到了那些类。我应该怎么做,需要看那些教程。最好能附几个例子。谢谢

解决方案 »

  1.   

    打开.net的帮助手册,在Contents卡片中
    Visual Studio .NET >> .NET框架 >> 使用 .NET 框架编程 >> 绘制和编辑图象在这一节内容里详细讲述了GDI的应用,而且有不少例子,自己慢慢看吧我是在VS2003下用2002的帮助手册,地址是:ms-help://MS.VSCC.2003/MS.MSDNVS.2052/cpguide/html/cpcondrawingeditingimages.htm
      

  2.   

    我喜欢用vml来做,
    推荐看看VML极道教程
      

  3.   

    1:你可以使用owc相关的组件
    2:你可以搜索现有的组件
    3:你可以自己写(比较罗嗦的说)
      

  4.   

    wwww.codeproject.com上有个有源码的组件做的很好,具体地址记不清了
      

  5.   

    可以自己写,以下是我做过的一个画饼行图的事例。代码有点长,using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Configuration;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Lin;
    namespace test
    {
    /// <summary>
    /// Chart_1 的摘要说明。
    /// </summary>
    public class WebVisitDayCake: System.Web.UI.Page
    {
    Lin.DateAndTime Dtime=new Lin.DateAndTime(); SqlConnection sqlcon=new SqlConnection(); private void Page_Load(object sender, System.EventArgs e)
    {
    sqlcon.ConnectionString=StrConnDataBase();
    try
    {
    sqlcon.Open();
    }
    catch(Exception ee)
    {
    Response.Write(ee.ToString()+"<br>");
    }
    //页面加载时,初始化数据库连接字符串; Chart();
    //加载图形;
    }
    protected void Chart()
    {
    int i;  //声明整型变量i
            
    Bitmap objBitMap=new Bitmap(400,400); //创建一个位图对象,用来放置柱形图,我们可以把它看作是一块画布。
    //'这里宽、高分别是400和200,当然,你也可以根据需要把它们做为参数来进行传递。
     
    Graphics objGraphics;
     
    //声明一个图形对象,在上面创建的位图上画图。 

    objGraphics = Graphics.FromImage(objBitMap); //从指定的objBitMap对象创建新图形对象objGraphics。 objGraphics.Clear(Color.White); //清除整个绘图面并以指定白色为背景色进行填充。//          创建一个数据源,这里我们为了方便其间,采用数组做为柱形图和饼图的数据源。
    float fltMonth,fltYear;
                 
    fltMonth=Convert.ToSingle(System.DateTime.Now.Month.ToString()); fltYear=Convert.ToSingle(System.DateTime.Now.Year.ToString()); int DayCount;
    string StrSQlCount="select count(id) from WebVisitedCount where VisitMonth = '"+fltMonth+"' and VisitYear = '"+fltYear+"'";//本月的天数

    SqlDataAdapter SDA = new SqlDataAdapter(StrSQlCount,sqlcon);
    DataSet DS =new DataSet();
    SDA.Fill(DS,"WebVisitedCount");
                
    DayCount=Convert.ToInt16(DS.Tables["WebVisitedCount"].Rows[0][0]);
                //得到本月的天数

    string StrSQlDay="select * from WebVisitedCount where VisitMonth = '"+fltMonth+"' and VisitYear = '"+fltYear+"' order by VisitDay";//本月的每日访问量
                
    SqlDataAdapter SDADay = new SqlDataAdapter(StrSQlDay,sqlcon);
    DataSet DSDay =new DataSet(); SDADay.Fill(DSDay,"WebVisitedCount");
                        
                
    int[] arrValues =new int[DayCount];//访问量数据 string[] arrValueNames =new string[DayCount];//定义数组对象,用来描述月份 for(int j=0;j<DayCount;j++)
    {
    arrValues[j] = Convert.ToInt16(DSDay.Tables["WebVisitedCount"].Rows[j][4]);//日访问量数据
                  
                    arrValueNames[j] = Convert.ToString(DSDay.Tables["WebVisitedCount"].Rows[j][1]);//日期数据
    }
               
                string SqlStrMax_3="SELECT TOP 3 * FROM WebVisitedCount WHERE (VisitYear = '"+fltYear+"') AND (VisitMonth = '"+fltMonth+"') ORDER BY VisitCount DESC";//最大前三个 SqlDataAdapter SDAMax_3 = new SqlDataAdapter(SqlStrMax_3,sqlcon);
    DataSet DSMax_3 =new DataSet(); SDAMax_3.Fill(DSMax_3,"WebVisitedCount");
                 
    int RowCount;
                RowCount=DSMax_3.Tables["WebVisitedCount"].Rows.Count;
                string StrMaxText="",StrMMinText="";//说明文字
    string StrMax_3="",StrMin_3="";//日期和访问次数
    if(RowCount>=3)
    {
             StrMaxText="最高的三天:";
    StrMMinText="最低的三天:";

                
    for(int k=0;k<RowCount;k++)
    {
    StrMax_3 +=DSMax_3.Tables["WebVisitedCount"].Rows[k][1].ToString()+"号"+DSMax_3.Tables["WebVisitedCount"].Rows[k][4].ToString()+"次; ";
    } string SqlStrMin_3="SELECT TOP 3 * FROM WebVisitedCount WHERE (VisitYear = '"+fltYear+"') AND (VisitMonth = '"+fltMonth+"') ORDER BY VisitCount ";//最小前三个 SqlDataAdapter SDAMin_3 = new SqlDataAdapter(SqlStrMin_3,sqlcon);
    DataSet DSMin_3 =new DataSet(); SDAMin_3.Fill(DSMin_3,"WebVisitedCount"); for(int h=0;h<RowCount;h++)
    {
    StrMin_3 +=DSMin_3.Tables["WebVisitedCount"].Rows[h][1].ToString()+"号"+DSMin_3.Tables["WebVisitedCount"].Rows[h][4].ToString()+"次; ";
    }
    }
     
    objGraphics.DrawString("本月的日访问量比例图",new Font("宋体",9), Brushes.Black,new PointF(10, 5)); objGraphics.DrawString(StrMaxText+StrMax_3.Trim(),new Font("宋体",9), Brushes.Black,new PointF( 20,320)); objGraphics.DrawString(StrMMinText+StrMin_3.Trim(),new Font("宋体",9), Brushes.Black,new PointF( 20,300)); //在画布(objBitMap对象)的坐标5,5处,用指定的Brush(画笔)对象和Font(字体)对象绘制统计图标题。

    float sglCurrentAngle = 0;
    float sglTotalAngle  = 0;
    //上面画饼图。先定义两个变量,代表当前角度和总角度,以便于画图时将角度进行按比例换算。

    float sglTotalValues = 0;
    //定义一个变量,代表总量。

    for (i = 0;i< arrValues.Length;i++)
    {
    sglTotalValues += arrValues[i];
    }
    //计算总量。
    i = 0;       
    for(i = 0;i< arrValues.Length;i++)
    { //计算当前角度值: 本月的总访问量/本月的访问天数  * 360,得到饼图中当月所占的角度大小。 
    sglCurrentAngle = arrValues[i] / sglTotalValues * 360; //画出填充圆弧。
    objGraphics.FillPie(new SolidBrush(GetColor(i)),100,60,200, 200, sglTotalAngle, sglCurrentAngle);
    //画出填充路径。
    //
    // SolidBrush redBrush = new SolidBrush(Color.Red);
    //
    // GraphicsPath graphPath = new GraphicsPath(); //画出圆弧线。
    objGraphics.DrawPie(Pens.Black,100,60, 200, 200, sglTotalAngle, sglCurrentAngle); //把当前圆弧角度加到总角度上。
    sglTotalAngle += sglCurrentAngle;
    }
    //遍历数据源的每一项数据,并根据数据的大小画出饼图。
    //图形对象的FillPie()方法和DrawPie()在.NET 框架类库中已重载。
     
    objBitMap.Save(Response.OutputStream, ImageFormat.Gif); //将objGraphics对象以指定的图形格式(这里是Gif)保存到指定的Stream对象,并输出到客户端。
    }
      

  6.   

    public Color GetColor(int itemIndex)

    Color objColor=Color.Blue;;
    switch (itemIndex)
    {
      
    case 0:
    objColor = Color.FromArgb(153,204,51);
    break;
    case 1:
    objColor = Color.AntiqueWhite;
    break;
    case 2:
    objColor = Color.Aqua;
    break;
    case 3:
    objColor = Color.Aquamarine;
    break;
    case 4:
    objColor = Color.Azure;
    break;
    case 5:
    objColor = Color.Azure;
    break;
    case 6:
    objColor = Color.Beige;
    break;
    case 7:
    objColor = Color.Bisque;
    break;
    case 8:
    objColor = Color.Black;
    break;
    case 9:
    objColor = Color.BlanchedAlmond;
    break;
    case 10:
    objColor = Color.Blue;
    break;
    case 11:
    objColor = Color.BlueViolet;
    break;
    case 12:
    objColor = Color.Brown;
    break;
    case 13:
    objColor = Color.YellowGreen;
    break;
    case 14:
    objColor = Color.CadetBlue;
    break;
    case 15:
    objColor = Color.Chartreuse;
    break;
    case 16:
    objColor = Color.Chocolate;
    break;
    case 17:
    objColor = Color.Coral;
    break;
    case 18:
    objColor = Color.CornflowerBlue;
    break;
    case 19:
    objColor = Color.Cornsilk;
    break;
    case 20:
    objColor = Color.Crimson;
    break;
    case 21:
    objColor = Color.Cyan;
    break;
    case 22:
    objColor = Color.DarkBlue;
    break;
    case 23:
    objColor = Color.DarkCyan;
    break;
    case 24:
    objColor = Color.DarkGoldenrod;
    break;
    case 25:
    objColor = Color.Chartreuse;
    break;
    case 26:
    objColor = Color.Chocolate;
    break;
    case 27:
    objColor = Color.Coral;
    break;
    case 28:
    objColor = Color.CornflowerBlue;
    break;
    case 29:
    objColor = Color.Cornsilk;
    break;
    case 30:
    objColor = Color.Crimson;
    break;
    case 31:
    objColor = Color.Cyan;
    break;
    default:
    objColor = Color.FromArgb(153,204,51);
    break;
    }
    return objColor;
    }
    public string StrConnDataBase()
    {
    string s_DatePath ,s_DateName,s_Name,s_Password,s_Connstr;
    s_DatePath = ConfigurationSettings.AppSettings["databasepath"];
    s_Name = ConfigurationSettings.AppSettings["user"];
    s_Password = ConfigurationSettings.AppSettings["pwd"];
    s_DateName = ConfigurationSettings.AppSettings["datebasename"];
    s_Connstr = "server = " + s_DatePath + ";uid = "+s_Name+";pwd = " + s_Password + ";database = "+ s_DateName; return s_Connstr;

    //数据库连接字符串  }
    private void Page_UnLoad(object sender, System.EventArgs e)
    {
    try
    {
    sqlcon.Close();
    }
    catch(Exception ee)
    {
    Response.Write(ee.ToString()+"<br>");
    }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
                this.Unload +=new EventHandler(this.Page_UnLoad);
    }
    #endregion
    }
    }