在Vs2010 建立Asp.net 4.0 Chart圖表

摘要:在Vs2010 建立Asp.net 4.0 Chart圖表

##########################  web.config  #########################################

  <appSettings>   <add key="ChartImageHandler" value="storage=file ;Url=~/chartImg/;" /> </appSettings>    圖表暫存實體位置

 

  <pages controlRenderingCompatibilityVersion="4.0" theme="ToeicWeb"
       clientIDMode="AutoID">
       <controls>
          <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
             assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
       </controls>
    </pages>

 <handlers>
      <remove name="ChartImageHandler" />
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
        path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>

 

#####################     介面   #############################

  <asp:Chart ID="chartdiagnosis" runat="server" Width="680px" Height="400px" BackColor="White">
        <Titles>
            <asp:Title Text="我的診斷書">
            </asp:Title>
        </Titles>
        <Series>
            <asp:Series Name="答對率" BorderColor="GrayText" Color="#ff9900" IsValueShownAsLabel="true"
                ChartType="Area" />
        </Series>
        <Legends>
            <asp:Legend Enabled="True" IsTextAutoFit="False" Name="Default" BackColor="#ff9900"
                Font="Trebuchet MS, 8.25pt, style=Bold">
            </asp:Legend>
        </Legends>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderWidth="0" BackColor="#eaeaea"
                ShadowColor="Gray">
            </asp:ChartArea>
        </ChartAreas>
    </asp:Chart>

 

###################  程式   ##############################

 

      string[] ClassArrary = new string[] { "環境覺知\\n與敏感(初)", "環境概念\\n知識(初)", "環境價值觀\\n與態度(初)", "環境行動\\n技能(初)", "環境行動\\n經驗(初)", "環境知識\\n(中/高)", "綠色消費\\n(中/高)", "環境行為與技能\\n(中/高)" };
        string[][] arr = new string[5][];
        // X軸設定
        chartdiagnosis.ChartAreas[0].AxisX.Title = "知識類別";
        chartdiagnosis.ChartAreas[0].AxisX.ToolTip = "知識類別";

        // Y軸設定
        chartdiagnosis.ChartAreas[0].AxisY.ToolTip = "答對%";
        chartdiagnosis.ChartAreas[0].AxisY.Maximum = 100;
        chartdiagnosis.ChartAreas[0].AxisY.Minimum = 0;


        //知識直條圖新增
        int xindex = 0, xmaxindex = 8, count = 0;

        for (int i = xindex; i < xmaxindex; i++)
        {
            Random rand = new Random();
            chartdiagnosis.Series["答對率"].Points.AddXY(ClassArrary[i],26);
            //chartdiagnosis.Series["答對率"].Points[count].Color = System.Drawing.Color.Red;  // (初級)顏色設定

            chartdiagnosis.Series["答對率"].Points[count].ToolTip = "tooltip12"+i.ToString();//知識直條圖 ToolTip

            count++;
        }

######################################################################################

 

推薦網址: http://www.stackdoc.com/a/bianchengyuyan/ASP/20101023/55479.html