close
我有一部Windows 2000 Server,只能安裝到.NET Framework 2.0,所以無法安裝Microsoft Chart Controls for Microsoft .NET Framework 3.5,試出以下此法可讓.NET Framework 2.0主機也可以使用Microsoft Chart Controls。
 
1. 找一台已安裝Microsoft Chart Controls for Microsoft .NET Framework 3.5的主機,或下載Microsoft Chart Controls for Microsoft .NET Framework 3.5安裝到有Framework 3.5的主機上。
 
2. 複製C:\Program Files\Microsoft Chart Controls\Assemblies\下的System.Web.DataVisualization.Design.dllSystem.Web.DataVisualization.dll.NET 2.0主機上IIS Webbin目錄下。

 

3. 專案Web.Config增加如下

  <controls>增加

                <controls>

                      <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

                </controls>

  <httpHandlers>增加

                <httpHandlers>

                      <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

                </httpHandlers>

 

4. Server端,建立C:\TempImageFiles目錄

 

5. 程式如在Framework 3.5上寫的一樣

 

test1.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test1.aspx.cs" Inherits="test1" debug="True" %>

<html>

<head>

<title></title>

</head>

<body bgcolor="#ffffff">

 

<form id="form1" runat="server">

<asp:chart id="Chart1" runat="server" Height="296px" Width="612px" Palette="BrightPastel" imagetype="Png" BorderDashStyle="Solid" BackSecondaryColor="White" BackGradientStyle="TopBottom" BorderWidth="2" backcolor="#D3DFF0" BorderColor="26, 59, 105">

<titles>

<asp:Title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 14.25pt, style=Bold" ShadowOffset="3" Text="" ForeColor="26, 59, 105"></asp:Title>

</titles>

<legends>

<asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:Legend>

<asp:Legend Docking="Top" Name="Legend1" BackColor="Transparent"></asp:Legend>

<asp:Legend Docking="Right" Name="Legend2" BackColor="Transparent"></asp:Legend>

</legends>

<borderskin skinstyle="Emboss"></borderskin>

<series>

<asp:Series Name="test_column" BorderColor="180, 26, 59, 105" LegendText="PC數" Legend="Legend1" ChartType="Column">

<points>

</points>

</asp:Series>

</series>

<chartareas>

<asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent" BackGradientStyle="TopBottom">

<area3dstyle Rotation="10" perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False"></area3dstyle>

<axisy linecolor="64, 64, 64, 64">

<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />

<majorgrid linecolor="64, 64, 64, 64" />

</axisy>

<axisx linecolor="64, 64, 64, 64">

<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />

<majorgrid linecolor="64, 64, 64, 64" />

</axisx>

</asp:ChartArea>

</chartareas>

</asp:chart>

</form>

 

</body>

</html>

 

 

test1.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.Web.UI.DataVisualization.Charting;

 

public partial class test1: System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

//設定Chart Title-------------------------------------------------

Chart1.Titles[0].Text = "PC數量統計";

//設定Axis Title-------------------------------------------------

Chart1.ChartAreas["ChartArea1"].AxisX.Title = "月份";

Chart1.ChartAreas["ChartArea1"].AxisY.Title = "數量";

//手動建立第一個新的data series及設定屬性-------------------------

Series series = new Series("Spline");

series.ChartType = SeriesChartType.Spline;

series.BorderWidth = 3;

series.ShadowOffset = 2;

series.LegendText = "test筆數曲線";

// Populate new series with data

series.Points.AddY(55);

series.Points.AddY(67);

series.Points.AddY(22);

// Add series into the chart's series collection

Chart1.Series.Add(series);

//手動建立第二個新的data series及設定屬性-------------------------

Series series_2 = new Series("Line");

series_2.ChartType = SeriesChartType.Line;

series_2.BorderWidth = 3;

series_2.ShadowOffset = 2;

series_2.LegendText = "test折線";

Chart1.Series.Add(series_2);

series_2.Points.AddY(45.0);

series_2.Points.AddY(39.1);

series_2.Points.AddY(90);

series_2.Points.AddY(45.4);

series_2.Points.AddY(91.6);

series_2.Points.AddY(208.6);

series_2.Points.AddY(178.3);

Chart1.Series["Line"].IsValueShownAsLabel = true;

//手動建立條狀圖值------------------------------------------------

Chart1.Series["test_column"].Points.Add(Convert.ToInt32(50));

Chart1.Series["test_column"].Points.Add(Convert.ToInt32(80));

Chart1.Series["test_column"].Points.Add(Convert.ToInt32(30));

Chart1.Series["test_column"].Points.Add(Convert.ToInt32(100));

Chart1.Series["test_column"].IsValueShownAsLabel = true;

}

}

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 adamschen9921 的頭像
    adamschen9921

    昶達的部落格

    adamschen9921 發表在 痞客邦 留言(0) 人氣()