http://www.jq-school.com/Show.aspx?id=311
本文章由jquery学堂2群的网友【北京-web-小虾米】整理分享,非常感谢!
效果图:



1、柱形图:
html代码如下 :
01 | < asp:Chart ID = "Chart1" runat = "server" ImageType = "Jpeg" ChartDashStyle = "solid" |
02 | Height = "320px" style = "margin-bottom: 0px" Width = "614px" > |
04 | < asp:Legend Name = "Legend1" > |
10 | < asp:ChartArea Name = "ChartArea1" > |
12 | < MajorTickMark Enabled = "False" LineColor = "White" LineDashStyle = "NotSet" /> |
13 | < MajorGrid Enabled = "false" /> |
14 | < MinorTickMark LineColor = "White" /> |
17 | < MajorTickMark LineColor = "White" /> |
18 | < MajorGrid Enabled = "False" /> |
19 | < MinorTickMark LineColor = "White" /> |
24 | < asp:Title Name = "Title1" > |
后台代码如下:
05 | Chart1.ChartAreas[ "ChartArea1" ].BorderColor = Color.Black; |
06 | Chart1.ChartAreas[ "ChartArea1" ].BorderWidth = 2; |
07 | Chart1.ChartAreas[0].AxisX.Interval = 1; |
08 | Chart1.ChartAreas[0].AxisX.IntervalOffset = 1; |
09 | Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true ; |
11 | Chart1.Series.Add( "实际值" ); |
12 | Chart1.Series[ "实际值" ][ "PixelPointWidth" ] = "20" ; |
13 | Chart1.Series[ "实际值" ].Points.DataBindXY(list1, list2); |
14 | for (int i = 0; i < list1.Count; i++) |
16 | Chart1.Series[ "实际值" ].Points[i].Label = list2[i].ToString(); |
20 | Chart1.ChartAreas[ "ChartArea1" ].AxisY.TitleFont = new Font( "微软雅黑" , float.Parse( "8" ), FontStyle.Regular); |
21 | Chart1.ChartAreas[ "ChartArea1" ].AxisY.TitleForeColor = Color.FromName( "Black" ); |
22 | Chart1.ChartAreas[ "ChartArea1" ].AxisY.Title = "单位;" + "万千瓦时" ; |
23 | Chart1.ChartAreas[ "ChartArea1" ].AxisX.TitleFont = new Font( "微软雅黑" , float.Parse( "8" ), FontStyle.Regular); |
24 | Chart1.ChartAreas[ "ChartArea1" ].AxisX.TitleForeColor = Color.FromName( "Black" ); |
25 | Chart1.ChartAreas[ "ChartArea1" ].AxisX.Title = date + "发电量" ; |
2、拆线图:
只需要增加Series以及Series的图标类型(Series.ChartType = SeriesChartType.Line)和数据源即可。
3、饼图:
html代码如下:
01 | < asp:Chart ID = "Chart2" runat = "server" ImageType = "Jpeg" ChartDashStyle = "solid" |
02 | Height = "322px" Width = "440px" onclick = "Chart2_Click" > |
04 | < asp:Legend Name = "Legend1" > |
10 | < asp:ChartArea Name = "ChartArea1" > |
14 | < asp:Title Name = "Title1" > |
后台代码如下:
10 | string createdate = StringHelper.GetCurrentDate( "yyyy-MM-dd" ); |
11 | string date = StringHelper.AddDate( "d" , -1, createdate, "yyyy-MM-dd" ); |
13 | Series series = Chart2.Series.Add( "My Series" ); |
14 | series.ToolTip = "#VALX:#VALY 万千瓦时" ; |
15 | series.LegendToolTip = "#PERCENT" ; |
16 | series.PostBackValue = "#INDEX" ; |
17 | series.LegendPostBackValue = "#INDEX" ; |
18 | series.LegendText= "#VALX" ; |
19 | series.Label = "#VALX[#PERCENT]" ; |
20 | series.Points.DataBindXY(list1, list2); |
21 | Chart2.Series[0][ "PieLabelStyle" ] = "Outside" ; |
22 | series.ChartType = SeriesChartType.Pie; |
23 | series.ShadowOffset = 2; |
24 | series.BorderColor = Color.DarkGray; |