Recently, I was working on Indicator Management. There was a function of measuring indicator completion volume. By accident, I found the mschart control. After downloading it, I tried it and found it useful. I could make a very beautiful chart. You can set a lot of options, and the built-in samples has a lot of beautiful styles. Use it quickly.
PS: I bought Dundas. Microsoft is rich.
: Http://www.microsoft.com/downloads/details.aspx? Displaylang = ZH-CN & familyid = 130f7986-bf49-4fe5-9ca8-910ae6ea442c
Pack: http://www.microsoft.com/downloads/details.aspx? Familyid = 581ff4e3-749f-4454-a5e3-de4c463143bd & displaylang = ZH-CN
Microsoft chart controls add-on for Microsoft Visual Studio 2008: http://www.microsoft.com/downloads/details.aspx? Familyid = 1d69ce13-e1e5-4315-825c-f14d33a303e9 & displaylang = en
Instance site: http://code.msdn.microsoft.com/mschart
I also wrote a sample, but I forgot where to go. There are also downloads on the site above.
Two useful articles from the nest of zookeeper: http://www.cnblogs.com/shuncy/archive/2008/11/07/1328738.html
Http://www.cnblogs.com/shuncy/archive/2008/11/10/1330827.html
Why can't I upload images.
Basic attributes to be set include:
1. Annotations -- a set of graphical annotations
2. chartareas-chart area set
3. Legends-legend set
4. Series -- a sequence set of charts (that is, a set of chart data objects)
5. Titles -- the title set of the icon
Because the sample contains a lot of beautiful styles, I can use them directly and modify the data binding part. I chose the following:
<Asp: Chart id = "chart1" runat = "server" backcolor = "# d3dff0" backgradientendcolor = "white" <br/> backgradienttype = "topbottom" borderlinecolor = "26, 59,105 "borderlinestyle =" solid "<br/> borderlinewidth =" 2 "Height =" 300px "imagetype =" PNG "imageurl = "~ /Tempimages/chartpic _ # seq (, 3) "<br/> palette =" brightpastel "width =" 600px "> <br/> <titles> <br/> <asp: title shadowcolor = "32, 0, 0, 0" font = "trebuchet MS, 14.25pt, style =" bold "mce_style =" bold "" forecolor = "26, 59,105 "> <br/> </ASP: title> <br/> </titles> <br/> <legends> <br/> <asp: legend name = "legend1" Docking = "TOP"> <br/> </ASP: legend> <br/> </legends> <br/> <borderskin skinstyle = "emboss"/> <br/> <Series> <br/> <asp: series chartarea = "default" legend = "legend1" name = "metrics of this month"> <br/> </ASP: Series> <br/> <asp: series chartarea = "default" legend = "legend1" name = "completions"> <br/> </ASP: series> <br/> </series> <br/> <chartareas> <br/> <asp: chartarea backcolor = "64,165,191,228" backgradientstyle = "topbottom" backsecondarycolor = "white" <br/> bordercolor = "64, 64, 64, 64 "borderdashstyle =" solid "name =" default "shadowcolor =" Transparent "> <br/> <axisy islabelautofit =" false "linecolor =" 64, 64, 64, 64 "& gt; <br/> <labelstyle font =" trebuchet MS, 8.25pt, style = "bold" mce_style = "bold"/> <br/> <majorgrid linecolor = "64, 64, 64, 64 "/> <br/> </axisy> <br/> <axisx islabelautofit =" false "linecolor =" 64, 64, 64, 64 "& gt; <br/> <labelstyle font =" trebuchet MS, 8.25pt, style = "bold" mce_style = "bold"/> <br/> <majorgrid linecolor = "64, 64, 64, 64 "/> <br/> </axisx> <br/> </ASP: chartarea> <br/> </chartareas> <br/> </ASP: chart> <br/>
It is a blue background and looks quite comfortable.
The above two articles have already mentioned several data binding methods. It is easier to bind dataset and other types, similar to binding drop-down lists, set the Y value field of the X value field.
Because I want to make a statistical chart, the indicators of each department or owner are ready-made, but the amount of completion is calculated, so I use the dynamic addition method when binding the gridview, each time a data row is bound, a point is added.
Statistical data: Here, you can set some chart attributes, such as label tilte. label indicates the information displayed on the Data bar. Generally, "# Val" is used by default, which is the default y value.
/// <Summary> <br/> // handles the Click Event of the btnsearch2 control. statistics by department per month <br/> /// </Summary> <br/> /// <Param name = "sender"> the source of the event. </param> <br/> // <Param name = "E"> the <see CREF = "system. eventargs "/> instance containing the event data. </param> <br/> protected void btnsearch2_click (Object sender, eventargs E) <br/>{< br/> // set whether to generate a chart <br/> If (this. chkchart2.checked = true) <br/>{< br/> // This. chart1.series [0]. name = "indicator of the current month"; <br/> // This. chart1.series [1]. name = "completions"; <br/> This. chart2.series [0]. label = "# Val"; <br/> This. chart2.series [1]. label = "# Val"; <br/> This. chart2.titles [0]. TEXT = This. ddl1_mentid2.selecteditem. text <br/> + this.txt searchindicatordate2start. text + "-" <br/> + this.txt searchindicatordate2end. text <br/> + this. ddlsearchsaletypeid2.selecteditem. text + "sales indicator completion Statistics"; <br/>}</P> <p> This. lblstrwhere2.text = "required mentid =" + this. ddl1_mentid2.selectedvalue <br/> + "and saletypeid =" + this. ddlsearchsaletypeid2.selectedvalue <br/> + "and indicatordate> = '" + this.txt searchindicatordate2start. text <br/> + "'and indicatordate <='" + this.txt searchindicatordate2end. text + "'"; <br/> chinamobile. bll. sales. departmentindicators BLL = new chinamobile. bll. sales. departmentindicators (); <br/> dataset DS = BLL. getlist (this. lblstrwhere2.text); <br/> This. mygridview2.datasource = Ds; <br/> This. mygridview2.databind (); <br/>}
Add a point when binding each row of data
/// <Summary> <br/> // handles the rowdatabound event of the mygridview2 control. <br/> /// </Summary> <br/> /// <Param name = "sender"> the source of the event. </param> <br/> // <Param name = "E"> the <see CREF = "system. web. UI. webcontrols. gridviewroweventargs "/> instance containing the event data. </param> <br/> protected void mygridview2_rowdatabound (Object sender, gridviewroweventargs e) <br/>{< br/> If (E. row. rowtype = datacontrolrowtype. datarow) <br/>{< br/> // display the Department <br/> label lbldepartment = (Label) (E. row. findcontrol ("lbldepartment"); <br/> lbldepartment. TEXT = This. ddl1_mentid2.selecteditem. text; <br/> // display the sales type <br/> label lblsaletypeinfo = (Label) (E. row. findcontrol ("lblsaletypeinfo"); <br/> lblsaletypeinfo. TEXT = This. ddlsearchsaletypeid2.selecteditem. text; <br/> // Display Indicator <br/> // label lblindicator = (Label) (E. row. findcontrol ("lblindicator"); <br/> chinamobile. bll. sales. departmentindicators BLL = new chinamobile. bll. sales. departmentindicators (); <br/> int required mentid = int. parse (this. mygridview2.datakeys [E. row. rowindex]. values ["dimension mentid"]. tostring (); <br/> string indicatordate = This. mygridview2.datakeys [E. row. rowindex]. values ["indicatordate"]. tostring (); <br/> // int Indicator = BLL. getindicator (extends mentid, Int. parse (this. ddlsearchsaletypeid2.selectedvalue), indicatordate); <br/> int Indicator = int. parse (this. mygridview2.datakeys [E. row. rowindex]. values ["indicator"]. tostring (); <br/> // display completed indicators <br/> label lblindicatoryes = (Label) (E. row. findcontrol ("lblindicatoryes"); <br/> label lblindicatorno = (Label) (E. row. findcontrol ("lblindicatorno"); <br/> label lblpercent = (Label) (E. row. findcontrol ("lblpercent"); </P> <p> If (indicator> 0) <br/>{< br/> // lblindicator. TEXT = indicator. tostring (); <br/> chinamobile. bll. sales. salerecord bllsr = new chinamobile. bll. sales. salerecord (); <br/> lblindicatoryes. TEXT = bllsr. getindicatoryes (specified mentid, Int. parse (this. ddlsearchsaletypeid2.selectedvalue), indicatordate ). tostring (); <br/> lblindicatorno. TEXT = bllsr. getindicatorno (specified mentid, Int. parse (this. ddlsearchsaletypeid2.selectedvalue), indicatordate ). tostring (); <br/> system. globalization. numberformatinfo GN = new system. globalization. cultureinfo ("ZH-CN", false ). numberformat; <br/> GN. percentdecimaldigits = 2; // retain two decimals <br/> lblpercent. TEXT = (decimal. parse (lblindicatoryes. text)/indicator )). tostring ("P", GN); <br/>}< br/> else <br/>{< br/> // lblindicator. TEXT = "not allocated this month"; <br/> chinamobile. bll. sales. salerecord bllsr = new chinamobile. bll. sales. salerecord (); <br/> lblindicatoryes. TEXT = bllsr. getindicatoryes (specified mentid, Int. parse (this. ddlsearchsaletypeid2.selectedvalue), indicatordate ). tostring (); <br/> lblindicatorno. TEXT = bllsr. getindicatorno (specified mentid, Int. parse (this. ddlsearchsaletypeid2.selectedvalue), indicatordate ). tostring (); <br/>}< br/> // set the chart <br/> If (this. chkchart2.checked = true) <br/>{< br/> This. chart2.series [0]. points. addxy (this. mygridview2.datakeys [E. row. rowindex] ["indicatordate"]. tostring (), indicator); <br/> This. chart2.series [1]. points. addxy (this. mygridview2.datakeys [E. row. rowindex] ["indicatordate"]. tostring (), double. parse (lblindicatoryes. text); <br/>}</P> <p >}< br/>}
Well, that's all. The above code binds the gridview. In fact, the last two or three rows add a point. This only generates a very simple chart. You can also set click events for each data row to display more detailed information.
Why can't I upload images.
Note that the following error may occur during release:
The temporary directory in the chart handler configuration [C:/tempimagefiles/] is invalid.
This is because the path generated by the image is set in webconfig and the webconfig file is modified.
Set <add key = "chartimagehandler" value = "Storage = file; timeout = 20; Dir = C:/tempimages/;"/>
Change the red part to <add key = "chartimagehandler" value = "Storage = file; timeout = 20; url = ~ /Tempimages/; "/>
The absolute path is used by default. It is better to change it to a relative path.
At the same time, assign permissions to the corresponding tempimages directory