图标控件的使用TeeChart

1.添加teechart到工具箱。
  步骤 工具箱上点右键,添加选项卡->选择项->选择teechart.dll确定即可。可以同时添加language.dll
2. 新建一个aspx页面,拖一个teechart到页面中,设置属性并添加个Button。代码如下:
<%@ Page Language="C#"   CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="TeeChart" Namespace="Steema.TeeChart.Web" TagPrefix="tchart" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <tchart:WebChart ID="WebChart1" runat="server" Width="800px"  Height="600px" GetChartFile="GetChart.aspx" TempChart="Session"  />
       
        <asp:Button ID="Button1" runat="server" Text="确定" οnclick="Button1_Click" />
    </div>
    </form>
</body>
</html>
3.假如我们想画一个折线图,添加后台代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Steema.TeeChart.Styles;//方便添加各种类型的曲线

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = GetData();//获取数据
        Line line = new Line();//teechart中的折线图
        foreach (DataRow dr in dt.Rows)//添加数据
        {
            line.Add(Convert.ToInt32(dr[0]), Convert.ToDouble(dr[1]));
        }
        WebChart1.Chart.Series.Add(line);//所有的曲线必须添加到 series中
        WebChart1.Chart.Aspect.View3D = false;//2D图片,否则是3D的
    }

    public DataTable GetData()//产生数据写的稍微有些麻烦
    {
        DataTable dt = new DataTable();
        DataColumn dc0 = new DataColumn("Year");
        DataColumn dc1 = new DataColumn("Value");
        dt.Columns.Add(dc0);
        dt.Columns.Add(dc1);
        Random r = new Random();
        Hashtable hashtable = new Hashtable();
        int RowNum = 10;
        for (int i = 0; hashtable.Count < RowNum; i++)
        {
            int value = r.Next(1, 50);
            if (!hashtable.Contains(value))
            {
                hashtable.Add(i, value);
            }
        }
        ArrayList keys = new ArrayList();
        foreach (int key in hashtable.Keys)
        {
            keys.Add(key);
        }
        for (int i = 2000; i < 2010; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = i;
            dr[1] = hashtable[keys[i-2000]];
           
            dt.Rows.Add(dr);
        }      
        return dt;
    }
}

TeeChart.dll下载

http://shop111521490.taobao.com/shop/view_shop.htm?spm=a1z0e.1.10010.4.sfsdzk


4.说明 teechart中有GetChartFile="GetChart.aspx" TempChart="Session" 这两个属性是必须设置。否则图片将是一个X。
GetChart.aspx是个固定的页面什么原理没有研究,贴出代码如下
前台:<%@ Page language="c#" Inherits="WebForm.GetChart" CodeFile="GetChart.aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN" >
  <html>
      <head runat="server">
    <title>GetChart</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body>
   
    <form method="post" runat="server">

     </form>
   
  </body>
</html>
后台:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;


namespace WebForm
{
    /// <summary>
    /// Summary description for GetChart.
    /// </summary>
    public partial class GetChart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // *************************************************************
            // Code to retrieve Session saved streamed Charts to a WebForm.
      // This code should be included if the WebChart 'UseStreams' property is set to True.
            // *************************************************************

            string chartName=Request.QueryString["Chart"];

            if (Session[chartName]!=null)
            {
                MemoryStream chartStream = new MemoryStream();
                chartStream=((MemoryStream)Session[chartName]);
                Response.OutputStream.Write(chartStream.ToArray(),0,(int)chartStream.Length);
                chartStream.Close();
                Session.Remove(chartName);
            }
        }

        #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()
        {   
        }
        #endregion
    }
}
运行之后效果如下所示:
<img src="https://img-blog.csdn.net/20140820145221125?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyOTA2Nw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值