初次使用ZedGraph

下载ZedGraph.dll : /Files/ProgrammerSystem/ZedGraph.dll.rar

BuildReport.aspx页面
<% @ Page Language="C#" AutoEventWireup="true" CodeFile="BuildReport.aspx.cs" Inherits="Count_BuildReport"  %>
<% @ Register TagPrefix="zgw" Namespace="ZedGraph.Web" Assembly="ZedGraph.Web"  %>
< ZGW:ZEDGRAPHWEB  id ="ZedGraphWeb1"  runat ="server"  width ="780"  Height ="260"  RenderMode ="RawImage"
 BarType
="Stack"  IsFontsScaled ="false"  IsShowTitle ="true"  BaseDimension ="10"   />

BuildReport.aspx.cs 类文件
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  ZedGraph;
using  ZedGraph.Web;

public  partial  class  Count_BuildReport : System.Web.UI.Page
{
    
private string _serverName = "";
    
private string _startTime = "";
    
private string _endTime = "";

    
public string ServerName get return this._serverName; } set this._serverName = value; } }
    
public string StartTime get return this._startTime; } set this._startTime = value; } }
    
public string EndTime get return this._endTime; } set this._endTime = value; } }

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!this.Page.IsPostBack)
        
{
            
接受参数
        }

    }


    
WebForm Designer generated code


    
private void OnRenderGraph(ZedGraphWeb zgw, Graphics g, MasterPane masterPane)
    
{
        GraphPane myPane 
= masterPane[0];

        
报表相关属性设置

        
//从数据库中取出数据
        DataSet ds = ManageAnalyzeDAL.CountDAL.GetOnlineCount(_serverName, _startTime, _endTime);
        DataTable dt 
= ds.Tables[0];
        DataTable dtTopOnlineCount 
= ds.Tables[1]; //某天中最高值

        
int dtRows = dt.Rows.Count / 24//获取天数

        PointPairList[] list 
= new PointPairList[dtRows];

        
for (int i = 0; i < dtRows; i++)
        
{
            
int startNum = i * 24;
            
int endNum = (i + 1* 24 - 1;

            list[i] 
= new PointPairList();

            
double intTopCount = Convert.ToDouble(dtTopOnlineCount.Rows[i]["onlineCount"]);

            
获取某天24小时的点
        }


        LineItem[] lineItem 
= new LineItem[dtRows];

        
for (int i = 0; i < dtRows; i++)
        
{
            lineItem[i] 
= myPane.AddCurve(Convert.ToDateTime(dt.Rows[i * 23 + i]["WriteTime"]).ToShortDateString(), (PointPairList)list[i], getColor(i),SymbolType.Star);
        }
            
        masterPane.AxisChange(g);
    }


    
DrawText

    
getColor
}


你可能感兴趣的:(Graph)