asp.net Microsoft Chart control using sample code sharing _ Practical Tips

Source: Internet
Author: User

Copy Code code as follows:

<configuration>
<system.webServer>
<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 "/>
</system.webServer>
<system.web>
<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"/>
</system.web>
</configuration>

Copy Code 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 ">

<title>mschart Chart Control </title>
<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=" 26, 59, ">
<Titles>
<asp:title "Microsoft Ya Black, 16pt" name= "Title1" text= "Statistics" >
</asp:Title>
</Titles>
<borderskin skinstyle= "Emboss" ></borderskin>
<Series>
<asp:series name= "Series1" charttype= "Bubble" markersize= "8" markerstyle= "Circle" >
</asp:Series>
</Series>
<ChartAreas>
<asp:chartarea name= "ChartArea1" bordercolor= "," "backsecondarycolor=" Transparent "backcolor=" 64, 165, 191, 228 "shadowcolor=" Transparent backgradientstyle= "Topbottom" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

<asp:chart id= "Chart2" runat= "Server" >
<Series>
<asp:series name= "Series1" >
</asp:Series>
</Series>
<ChartAreas>
<asp:chartarea name= "CHARTAREA1" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br/>

<asp:chart id= "CHART3" runat= "Server" >
<Series>
<asp:series name= "Series1" >
</asp:Series>
</Series>
<ChartAreas>
<asp:chartarea name= "CHARTAREA1" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

<asp:chart id= "CHART4" runat= "Server" >
<Legends>
<asp:legend title= "Gold medal list" ></asp:Legend>
</Legends>
<Series>
<asp:series name= "Series1" >
</asp:Series>
</Series>
<ChartAreas>
<asp:chartarea name= "CHARTAREA1" >
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
</body>

Copy Code code 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)
{
#region Line Chart
Chart1.datasource = dt;//bound 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;//Sets the name of the y-axis title to a location far away
chart1.chartareas["ChartArea1"]. Axisy.title = "Gold medal";//x axis Title
chart1.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Sets the name of the y-axis title to a location far away
chart1.chartareas["ChartArea1"]. Axisx.interval = spacing of 1;//x axis data
chart1.chartareas["ChartArea1"]. AxisX.MajorGrid.Enabled = false;//does not show vertical split line
Chart1.series[0]. Isvalueshownaslabel = true;//Display coordinate value
#endregion
}


protected void GetStyle2 (DataTable dt)
{
#region spline (smooth curve)
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;//The style of the 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;//Sets the name of the y-axis title to a location far away
chart2.chartareas["ChartArea1"]. Axisy.title = "Gold medal";//x axis Title
chart2.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Sets the name of the y-axis title to a location far away
chart2.chartareas["ChartArea1"]. Axisx.interval = spacing of 1;//x axis data
chart2.chartareas["ChartArea1"]. AxisX.MajorGrid.Enabled = false;//does not show vertical split line
Chart2.series[0]. Isvalueshownaslabel = true;//Display coordinate value
#endregion
}

protected void GetStyle3 (DataTable dt)
{
#region Bar Chart
Chart3.datasource = dt;//bound data
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;//Sets the name of the y-axis title to a location far away
chart3.chartareas["ChartArea1"]. Axisy.title = "Gold medal";//x axis Title
chart3.chartareas["ChartArea1"]. Axisy.titlealignment = stringalignment.far;//Sets the name of the y-axis title to a location far away
chart3.chartareas["ChartArea1"]. Axisx.interval = spacing of 1;//x axis data
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;//bound data
chart4.series["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 National
Chart4.series[0]. Isvalueshownaslabel = true;//Display coordinate value
#endregion

}
<summary>
Create a two-dimensional datasheet
</summary>
<returns>datatable Types of data tables </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++)
{
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.