The steps are as follows:
1.
Chart control (a) example of a chart control application in an ASP. NET Web site (C # language) "title=" VS2010 Chart control (a) example of the application of the chart control in an ASP. NET Web site (C # language) "Action-data=" http%3a%2f%2fs8.sinaimg.cn%2fmw690%2f6988593etx6dhzwsoatc7%26690 "action-type=" Show-slide "style=" margin:0px; padding:0px; List-style:none; " >
2.
Chart control (a) example of a chart control application in an ASP. NET Web site (C # language) "title=" VS2010 Chart control (a) example of the application of the chart control in an ASP. NET Web site (C # language) "Action-data=" http%3a%2f%2fs12.sinaimg.cn%2fmw690%2f6988593etx6dhzxkdiv5b%26690 "action-type=" Show-slide "style=" margin:0px; padding:0px; List-style:none; " >
In the. NET Framework x.x, the chart control is added starting with version 4. (3.5 and earlier versions have no chart controls.) )
3. Drag the chart control directly between the default. aspx (the corresponding code is automatically generated during the drag process, and you modify it as needed).
Chart control (a) example of a chart control application in an ASP. NET Web site (C # language) "title=" VS2010 Chart control (a) example of a chart control's application in an ASP. NET Web site (C # language) "style=" margin : 0px; padding:0px; List-style:none; " >
Examples are as follows:
<<span style= "FONT-SIZE:9.5PT; Font-family:nsimsun; Background:yellow; Color:maroon; Mso-bidi-font-family:nsimsun; mso-font-kerning:0pt; Mso-highlight:yellow ">asp: Content id=" bodycontent "runat=" Server "contentplaceholderid=" MainContent " height= "400px" width= "500px" >
<<span style= "Background:yellow; Color:maroon; Mso-highlight:yellow ">asp:Chart id=" Chart1 "runat=" Server ">
<<span style= "Color:maroon" >Series>
<<span style= "Background:yellow; Color:maroon; Mso-highlight:yellow ">asp:seriesname=" Series1 "charttype=" Column "chartarea=" ChartArea1 ">
</<span style= "Background:yellow; Color:maroon; Mso-highlight:yellow ">asp:Series>
<<span style= "Color:maroon" >asp:series name= "Series2" charttype= "Column" chartarea= "ChartArea1" >
</<span style= "Color:maroon" >asp:Series>
</<span style= "Color:maroon" >Series>
<<span style= "Color:maroon" >ChartAreas>
<<span style= "Color:maroon" >asp:chartarea name= "ChartArea1" >
</<span style= "Color:maroon" >asp:ChartArea>
</<span style= "Color:maroon" >ChartAreas>
</<span style= "Color:maroon" >asp:Chart>
</<span style= "FONT-SIZE:9.5PT; Font-family:nsimsun; Color:maroon; Mso-bidi-font-family:nsimsun; Mso-font-kerning:0pt ">asp:content>
(The yellow part of the code is the code that is automatically generated in the default. aspx file during the drag chart control.) Where height and width are the height and width properties of the chart control, add the settings yourself. The number of pairs is related to the code in the background code "set the y axis of the chart", which is set to two, which is finally shown in two columns of comparison data in the result graph.
...
Debug= "false" targetframework= "4.0" >
...
(where the yellow part is the automatically generated code in the Web. config file during the drag chart control, set the debug state of the pink section to true if the Code requires debugging)
4, add the corresponding control implementation code in the corresponding Default.aspx.cs file.
(1) First add a namespace to the Default.Aspx.cs file:
using system.data;// The DataTable is in this namespace
(2) Add control implementation code:
protected void Page_Load (object sender, EventArgs e)
{
DataTable dt = Default (DataTable);
DT = createdatatable ();
Set up a data source for a chart
Chart1.datasource = DT;
Set the chart y-axis counterpart
Chart1.series[0]. Yvaluemembers = "Volume1";
CHART1.SERIES[1]. Yvaluemembers = "Volume2";
Set the chart x-axis counterpart
Chart1.series[0]. Xvaluemember = "Date";
Binding Data
Chart1.databind ();
}
Private DataTable createdatatable ()
{
Create a DataTable as the data source of the Chart control
DataTable dt = new DataTable ();
ADD three columns to the DataTable
Dt. Columns.Add ("Date");
Dt. Columns.Add ("Volume1");
Dt. Columns.Add ("Volume2");
DataRow Dr;
ADD rows to the table which contains some random data for demonstration
Dr = dt. NewRow ();
dr["Date"] = "Jan";
dr["Volume1"] = 3731;
dr["Volume2"] = 4101;
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Date" = "Feb";
dr["Volume1"] = 6024;
dr["Volume2"] = 4324;
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Date"] = "Mar";
dr["Volume1"] = 4935;
dr["Volume2"] = 2935;
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Date"] = "APR";
dr["Volume1"] = 4466;
dr["Volume2"] = 5644;
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Date"] = "may";
dr["Volume1"] = 5117;
dr["Volume2"] = 5671;
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Date"] = "June";
dr["Volume1"] = 3546;
dr["Volume2"] = 4646;
Dt. Rows.Add (DR);
return DT;
}
5, the debug results are as follows (where WebSite1 is the project name)
"/website1"Server error in the application.
to be
Chartimg.axd
An error occurred while executing the child request.
Description : An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code.
Exception Details :
System.Web.HttpException: An error occurred while performing a child request for Chartimg.axd.
Source Error :
执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
|
Stack Trace :
[HttpException (0x80004005): An error occurred while performing a child request for Chartimg.axd. ] System.Web.HttpServerUtility.ExecuteInternal (IHttpHandler handler, TextWriter writer, Boolean Preserveform, Boolean Setpreviouspage, virtualpath Path, virtualpath filePath, string physpath, Exception error, string querystringoverride) +3 059030 System.Web.HttpServerUtility.Execute (String path, TextWriter writer, Boolean Preserveform) +851 System.Web.UI.DataVisualization.Charting.ChartHttpHandler.EnsureInitialized (Boolean Hardcheck) +316 System.Web.UI.DataVisualization.Charting.Chart.GetImageStorageMode (+24) ...... |
VS2010 Chart Control (a) example of a chart control application in an ASP. NET Web site (C # language)