ZedGraph 與在asp.net 中的應用 Step by Step

來源:互聯網
上載者:User
/*Title: ZedGraph 在 web 中的應用
 *Author: AlvinYe
 *Date: Aug 27,2006
 *Description: ZedGraph 在 web 中的應用
 *Environment: WinXP sp2,Vs2005 pro,.netFramework 2.0
 *KeyWord: ZedGraph 在 web 中的應用 theme
 */

1.建立一個網站
2.引用ZedGraph.Web.dll 和 ZedGraph.dll 
在 www.ZedGraph.org 可以下載到 3修改default2.aspx 改為以下內容
<%@ Page Language="C#" CodeFile="Default2.aspx.cs" Inherits="Default2" Theme="" %>
<%@ Register TagPrefix="zgw" Namespace="ZedGraph.Web" Assembly="ZedGraph.Web" %>
<ZGW:ZEDGRAPHWEB id="ZedGraphWeb1" runat="server" width="500" Height="375" RenderMode="RawImage" /> 注意其中的Theme="" 如果你在web.config 中已經設定好theme的話預設所有頁都會先載入theme
因為我們這裡只要產生圖片,如果載入Theme 就會顯示錯誤,看到亂碼. 4.修改default.aspx.cs 改為
using System;
using System.Drawing; using ZedGraph;
using ZedGraph.Web; 

public partial class Default2 : System.Web.UI.Page
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
  }   #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
  }   /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
    this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph);   }
  #endregion   /// <summary>
  /// This method is where you generate your graph.
  /// </summary>
  /// <param name="masterPane">You are provided with a MasterPane instance that
  /// contains one GraphPane by default (accessible via masterPane[0]).</param>
  /// <param name="g">A graphics instance so you can easily make the call to AxisChange()</param>
  private void OnRenderGraph(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
  {
    // Get the GraphPane so we can work with it
    GraphPane myPane = masterPane[0];     myPane.Title.Text = "學期成績表";
    myPane.XAxis.Title.Text = "學期";
    myPane.YAxis.Title.Text = "成績";     PointPairList list = new PointPairList();
    PointPairList list2 = new PointPairList();
    PointPairList list3 = new PointPairList();     DataTable dt = BuildDt();     for (int i = 0; i < dt.Rows.Count; i++)
    {
      if (dt.Rows[i]["Id"].ToString() == "1")
      {
        list.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Alvin");
      }
      else if (dt.Rows[i]["Id"].ToString() == "2")
      {
        list2.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Robin");
      }
      else
      {
        list3.Add(Convert.ToDouble(dt.Rows[i]["XueQi"]), Convert.ToDouble(dt.Rows[i]["FenShu"]), "Jim");
      }
    }     LineItem MyLine = myPane.AddCurve("Alvin", list, Color.Red, SymbolType.HDash);
    LineItem MyLine2 = myPane.AddCurve("Robin", list2, Color.Green);
    LineItem MyLine3 = myPane.AddCurve("Jim", list3, Color.Blue);
    masterPane.AxisChange(g);
  }   private DataTable BuildDt()
  {
    DataTable dt = new DataTable("Students");
    dt.Columns.Add("Id");
    dt.Columns.Add("Name");
    dt.Columns.Add("XueQi");
    dt.Columns.Add("FenShu");     dt.Rows.Add(1, "Alvin", "1", 100);
    dt.Rows.Add(1, "Alvin", "2", 90);
    dt.Rows.Add(1, "Alvin", "3", 80);
    dt.Rows.Add(1, "Alvin", "4", 120);
    dt.Rows.Add(2, "Robin", "1", 120);
    dt.Rows.Add(2, "Robin", "2", 100);
    dt.Rows.Add(2, "Robin", "3", 90);
    dt.Rows.Add(2, "Robin", "4", 110);
    dt.Rows.Add(3, "Jim", "1", 80);
    dt.Rows.Add(3, "Jim", "2", 90);
    dt.Rows.Add(3, "Jim", "3", 130);
    dt.Rows.Add(3, "Jim", "4", 135);     return dt;   }
} 運行結果如下

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.