asp.net Microsoft Chart control using sample code sharing

Source: Internet
Author: User
Tags split

  This article mainly introduces the ASP.net Microsoft Chart control using the sample code, the need for friends can refer to the

  Code as follows: <configuration>   <system.webServer>     <handlers>       &L T;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>   </system.webServer>   <system.web>     <httpHandlers>       <add path= "Chartimg.axd" verb= "GET, Head,post "Type=" System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version =4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "        validate=" false "/>   & nbsp </httpHandlers>   </system.web> </configuration>     code as follows: <%@ Page language= "C #" autoeventwireup= "true" codefile= "Chart.aspx.cs" inherits= "chart"%>   <%@ Register Assembly= "System.Web.DataVisualization, version=4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35"     namespace= "System.Web.UI.DataVisualization.Charting" tagprefix= "ASP"%>   <! 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> MSChart Chart Controls </title> </head> <body>     <form id= "Form1" runat= "Server" >     <div>         <asp:chart id= "Chart1" runat= "Server" width= "500px" borderdashstyle= "Solid" Palette= "Brightpastel" imagetype= "Png"  backsecondarycolor= "white" backgradientstyle= "Topbottom" BorderWidth= "2" backcolor= "#D3DFF0" bordercolor= ">             <Titles>                 <asp:title "Microsoft Ya Hei, 16pt" Name= "Title 1 "text=" Tables >                 </asp:Title>         & nbsp   </Titles>             <borderskin skinstyle= "Emboss" ></borderskin >             <Series>                 < Asp:series name= "Series1"  charttype= "Bubble" markersize= "8" markerstyle= "Circle" >                 </asp:Series>             </Series>     &N Bsp       <ChartAreas>                 <asp:chartarea name= "Ch ArtArea1 " bordercolor=", "backsecondarycolor=" Transparent "backcolor=", 165, 191, 228 "shadowcolor=" "Transparent" Backgradientstyle= "Topbottom" >                 </asp:ChartArea>     &NBS P       </ChartAreas>         </asp:Chart>             <asp:chart id= "Chart2" runat= "Server" >             <Series>   &NBSP ;             <asp:series name= "Series1" >             &NBS P   </asp:Series>             </Series>           &N Bsp <ChartAreas>                 <asp:chartarea name= "ChartArea1" >                 </asp:ChartArea>             </CH artareas>         </asp:Chart>         <br/>       & nbsp   <asp:chart id= "CHART3" runat= "Server" >             <Series>     &NBSP ;           <asp:series name= "Series1" >               &NBS P </asp:Series>             </Series>             &L T chartareas>                 <asp:chartarea name= "ChartArea1" >   &NBS P             </asp:ChartArea>             </chartareas >         </asp:Chart>           <asp:chart id= "Chart4" runat= "se RVer ">         <Legends>             <asp:legend title=" Gold medal list " ></asp:Legend>         </Legends>             <series& Gt   &NBSp             <asp:series name= "Series1" >             &NBS P   </asp:Series>             </Series>           &N Bsp <ChartAreas>                 <asp:chartarea name= "ChartArea1" >                 </asp:ChartArea>             </CH artareas>         </asp:Chart>     </div>     </form> </bo dy> </html>     code is as follows: using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Data; Using System.Web.UI; Using System.Web.UI.WebControls; Add using System.Drawing;   public partial class Chart:System.Web.UI.Page {    protected void Page_Load (object sender, EventArgs E )     {        DataTable dt = Creatdata ();         GetStyle1 (DT);         GetStyle2 (DT);         GETSTYLE3 (DT);         GetStyle4 (DT);    }         protected void GetStyle1 (DataTable dt)     {      &N Bsp #region Line chart         Chart1.datasource = dt;//binding Data         chart1.series["Series1"] . ChartType = system.web.ui.datavisualization.charting.seriescharttype.line;//Set Chart type         Chart1.series[0]. Xvaluemember = "Country";//x axis data member columns         Chart1.series[0]. Yvaluemembers = "Score";//y axis data member columns         chart1.chartareas["ChartArea1"]. Axisx.title = "Country";//x axis title         chart1.chartareas["ChartArea1"]. Axisx.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart1.chartareas[" ChartArea1 "]. Axisy.title = "Gold medal";//x axis Title         chart1.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart1.chartareas[" ChartArea1 "]. Axisx.interval = 1;//x axis data spacing         chart1.chartareas["ChartArea1"]. AxisX.MajorGrid.Enabled = false;//does not show vertical split line         Chart1.series[0]. Isvalueshownaslabel = true;//Display coordinate value         #endregion    }         Prot ected void GetStyle2 (DataTable dt)     {        #region spline (smooth curve)       &NBS P Chart2.datasource = dt;//bound data         chart2.series["Series1"]. ChartType = system.web.ui.datavisualization.charting.seriescharttype.spline;//Set Chart type         chart2.series["Series1"]. MarkerStyle = system.web.ui.datavisualization.charting.markerstyle.cross;//style of Set point, cross         Chart2.series[0]. Xvaluemember = "Country";//x axis data member columns         Chart2.series[0]. Yvaluemembers = "Score";//y axis data member columns         chart2.chartareas["ChartArea1"]. Axisx.title = "Country";//x axis title         chart2.chartareas["ChartArea1"]. Axisx.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart2.chartareas[" ChartArea1 "]. Axisy.title = "Gold medal";//x Axis title         chart2.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart2.chartareas[" ChartArea1 "]. Axisx.interval = 1;//x axis data spacing         chart2.chartareas["ChartArea1"]. AxisX.MajorGrid.Enabled = false;//does not show vertical split line         Chart2.series[0]. Isvalueshownaslabel = true;//Display coordinate value         #endregion    }       protected V OID GetStyle3 (DataTable DT)     {        #region bar chart         Chart3.Dat Asource = dt;//bound data   &NBSP     chart3.series["Series1"]. ChartType = system.web.ui.datavisualization.charting.seriescharttype.bar;//Set Chart type         Chart3.series[0]. Xvaluemember = "Country";//x axis data member columns         Chart3.series[0]. Yvaluemembers = "Score";//y axis data member columns         chart3.chartareas["ChartArea1"]. Axisx.title = "Country";//x axis title         chart3.chartareas["ChartArea1"]. Axisx.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart3.chartareas[" ChartArea1 "]. Axisy.title = "Gold medal";//x Axis title         chart3.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Set the name of the y-axis title location is far from         chart3.chartareas[" ChartArea1 "]. Axisx.interval = 1;//x axis data spacing         chart3.chartareas["ChartArea1"]. AxisX.MajorGrid.Enabled = false;//does not show vertical split line         Chart3.series[0]. Isvalueshownaslabel = true;//Display coordinate value         #eNdregion    }         protected void GetStyle4 (DataTable dt)     {        #region pie chart         Chart4.datasource = dt;//binding Data         Chart4.ser ies["Series1"]. ChartType = system.web.ui.datavisualization.charting.seriescharttype.pie;//Set Chart type         Chart4.series[0]. Xvaluemember = "Country";//x axis data member columns         Chart4.series[0]. Yvaluemembers = "Score";//y axis data member columns         Chart4.series[0]. Legendmapareaattributes = "Country"; Show country         Chart4.series[0]. Isvalueshownaslabel = true;//Display coordinate value         #endregion      }    ///<sum mary>    ///Create a two-dimensional data table    ///</summary>    ///<returns>datatable type datasheet &L T;/returns>     protected DataTable Creatdata ()     {        datatable dt = NEW DataTable ();         DT. Columns.Add ("Country", System.Type.GetType ("System.String"));         DT. Columns.Add ("Score", System.Type.GetType ("System.String"));         string[] n = new string[] {"China", "United States", "Russia", "UK"};         string[] C = new string[] {"85", "80", "50", "35"};         for (int i = 0; i < 4; i++)         {        &NBSP ;   DataRow dr = dt. NewRow ();             dr["Country"] = N[i];             dr["Score"] = C[i];             DT. Rows.Add (DR);        }         return DT;    }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.