Some time ago, when the project was developed, some data needed to be counted and displayed in a graphical form as needed. Because it is an ASP, I found the MSChart Chart control, it is very convenient and practical, share.
Main components of the MSChart control
toolbar, locate the Chart control, drag it to the top
Once you drag and drop the chart control to the foreground, the powerful IDE helps you accomplish something
The System.Web.DataVisualization dynamic library is also referenced and added in the Web site configuration file, Web. config
Where the code added in the configuration file, in the official release of the site, to make a few changes, we will say in detail later.
For detailed MSChart parameters, you can view the MSDN documentation.
In the foreground code, add the control
<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 font=" Microsoft Ya Hei, 16pt "name=" Title1 "text=" * * * * * * </asp:Title> </Titles> <borderskin skinstyle= "Emboss" ></borderskin> <Series> <asp:series name= "Series1" charttype= "Bubble" markersize= "8" markerstyle= "Cir Cle "> </asp:Series> </Series> <ChartAreas> <as P:chartarea name= "ChartArea1" bordercolor= "64, 165, 191, 228," "backsecondarycolor=" Transparent "backcolor=" "Shadowcolor=" Transparent "backgradientstyle=" Topbottom "> </asp:ChartArea> </charta Reas> </asp:Chart>
In the background code, you first create a function that stores data and stores it in a DataTable.
Create a two-dimensional data table
Next, you do the data binding, property setting, and so on for the chart control.
Philosophy Map
Line Chart
The same way to implement several other graphs
Spline graph (smooth curve)
spline graph (smooth curve)
Bar chart
Bar Chart
Pie chart
1 #region Pie Figure 2 Chart4.datasource = dt;//bind data 3 chart4.series["Series1"]. ChartType = system.web.ui.datavisualization.charting.seriescharttype.pie;//Set Chart type 4 chart4.series[0]. Xvaluemember = "Language";//x axis data member column 5 chart4.series[0]. Yvaluemembers = "Count";//y axis data member column 6 Chart4.series[0]. LegendText = "Language"; 7 chart4.series[0]. Isvalueshownaslabel = true;//Displays the coordinate value 8 #endregion
For more chart examples, refer to the MSDN demo.
Microsoft Demohttp://code.msdn.microsoft.com/mschart
At the beginning of the article, when we talk about adding MSChart controls, the IDE automatically modifies the code in our web. config.
When we formally upload the site to the server, if we do not modify some places, there will be a MSChart error. I will modify the following code in Web. config
Change into
The purpose is to change the relative address to avoid the path error when uploading to the server.
Also need to add Tempimages folder under Solution
OK, the basic MSChart control is used in this way, more detailed use can refer to MSDN or Microsoft-provided demo.
ASP. NET Microsoft Chart control MSChart