ASP.NET中的MSChart 控件使用 (示例)

  最近公司要求做一个报表. 显示全年销售评估图表. 这一下子让我联想到了微软的MSChart控件,因为之前有过这方面的研究.所以做起来不是很费力. 准确的说是,没做一次 都有一次不同的启发,不同的感想吧 。也希望这次自己琢磨出来的东西,能对大家有好处!

     好了,一向不喜欢说废话的我,突然说了这么多.... 直接从项目里面粘贴源码吧!(偷懒)希望大家多多指教..谢谢!

    ASP.NET前台:

 
  
1 < div class = " myChartCss " >
2 < asp:Chart ID = " Chart1 " runat = " server " Width = " 1024px " >
3 < Series >
4 < asp:Series Name = " 销量 " >
5 </ asp:Series >
6 </ Series >
7 < ChartAreas >
8 < asp:ChartArea Name = " ChartArea1 " >
9 </ asp:ChartArea >
10 </ ChartAreas >
11 < Legends >
12 < asp:Legend Alignment = " Center " Docking = " Bottom " Name = " Legend1 " Title = " 销量分析 " >
13 </ asp:Legend >
14 </ Legends >
15 < Titles >
16 < asp:Title Font = " 微软雅黑, 16pt " Name = " Title1 " Text = " 法国皇家龙船总体销售评估表 " >
17 </ asp:Title >
18 </ Titles >
19 </ asp:Chart >
20 </ div >

后台 主要 源码:

 
  
1 /// <summary>
2 /// 绑定报表控件数据源
3 /// </summary>
4   public void BindData()
5 {
6 IList < Nop_Product > data = BindChartProduct();
7 #region 尚未用到
8 // ChartArea chartArea = SetChartAreaStyle("Chart1", true);
9 // List<int> data = Models.StaticModel.createStaticData();
10 // System.Web.UI.DataVisualization.Charting.Chart Chart2 = new System.Web.UI.DataVisualization.Charting.Chart();
11 // Chart2.Width = 412;
12 // Chart2.Height = 296;
13 // Chart2.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.ImageTag;
14 // Chart2.Palette = ChartColorPalette.BrightPastel;
15 // Title t = new Title("IMG source streamed from Controller", Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
16 // Chart2.Titles.Add(t);
17 // Chart2.ChartAreas.Add("Series 1");
18 // // Populate series with random data
19 // Random random = new Random();
20 // for (int pointIndex = 0; pointIndex < 10; pointIndex++)
21 // {
22 // Chart1.Series[0].Points.AddY(random.Next(45, 95));
23 // // Chart1.Series["Series2"].Points.AddY(random.Next(5, 75));
24 // }
25   #endregion
26 for ( int i = 0 ; i < data.Count; i ++ )
27 {
28 Chart1.Series[ 0 ].Points.AddY(data[i].Quantity);
29 }
30 Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
31 Chart1.BorderlineWidth = 2 ;
32 Chart1.BorderColor = System.Drawing.Color.Black;
33 Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
34 Chart1.BorderWidth = 2 ;
35 Chart1.ChartAreas[ " ChartArea1 " ].AxisX.MajorGrid.Enabled = false ; // 不显示竖着的分割线
36   Chart1.ChartAreas[ " ChartArea1 " ].AxisY.Title = " 销售数量(瓶) " ;
37 Chart1.ChartAreas[ " ChartArea1 " ].AxisX.Title = " 时间(yyyy-MM) " ;
38 #region 尚未用到
39 // Chart1.Legends.Add("酒种类");
40 // Legend legend = new Legend(ddrTypeName.SelectedValue);
41 // 26, 59, 105
42 // legend.BackColor = Color.Transparent; // Color.FromArgb(26, 59, 105, 0);
43 // legend.BorderColor = Color.Gray;
44 // legend.Font = new System.Drawing.Font("Trebuchet MS", float.Parse("8.25"), FontStyle.Bold, GraphicsUnit.World);
45 // legend.IsDockedInsideChartArea = true;
46 // legend.DockedToChartArea = ddrTypeName.SelectedValue;
47 // Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; // X轴数据显示间隔
48 // Chart1.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Days;
49 // Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffset = 0.0;
50 // Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffsetType = DateTimeIntervalType.Days;
51 #endregion
52 Chart1.ChartAreas[ " ChartArea1 " ].AxisX.LabelStyle.Format = " yyyy年MM月 " ;
53 Chart1.ChartAreas[ " ChartArea1 " ].AxisY.Interval = 20 ; // y轴数据显示间隔
54 Chart1.DataSource = data;
55 Chart1.Series[ 0 ].YValueMembers = " Quantity " ;
56 Chart1.Series[ 0 ].XValueMember = " CreatedOn " ;
57 Chart1.DataBind();
58 // Set series chart type
59 Chart1.Series[ 0 ].ChartType = SeriesChartType.Line;
60 // Chart1.Series["Series2"].ChartType = SeriesChartType.Spline;
61 // Set point labels
62 Chart1.Series[ 0 ].IsValueShownAsLabel = true ;
63 // Chart1.Series["Series2"].IsValueShownAsLabel = true;
64 // Enable X axis margin
65 Chart1.ChartAreas[ " ChartArea1 " ].AxisX.IsMarginVisible = true ;
66 // Enable 3D, and show data point marker lines
67 Chart1.ChartAreas[ " ChartArea1 " ].Area3DStyle.Enable3D = false ;
68 Chart1.Series[ 0 ][ " ShowMarkerLines " ] = " True " ;
69 // Chart1.Series["Series2"]["ShowMarkerLines"] = "True";

效果图如下:

2011050910380392.gif

在此,只写出自己研究所得. 如有不当之处,希望大家多多指教,共同进步.  谢谢

转载于:https://www.cnblogs.com/axing/archive/2011/05/09/MSChart.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值