ASP.NET中的MSChart 控件使用 (示例)
2011-05-09 10:41
204 查看
最近公司要求做一个报表. 显示全年销售评估图表. 这一下子让我联想到了微软的MSChart控件,因为之前有过这方面的研究.所以做起来不是很费力. 准确的说是,没做一次 都有一次不同的启发,不同的感想吧 。也希望这次自己琢磨出来的东西,能对大家有好处!
好了,一向不喜欢说废话的我,突然说了这么多.... 直接从项目里面粘贴源码吧!(偷懒)希望大家多多指教..谢谢!
ASP.NET前台:
后台 主要 源码:
效果图如下:
在此,只写出自己研究所得. 如有不当之处,希望大家多多指教,共同进步. 谢谢
好了,一向不喜欢说废话的我,突然说了这么多.... 直接从项目里面粘贴源码吧!(偷懒)希望大家多多指教..谢谢!
ASP.NET前台:
<div class="myChartCss"> <asp:Chart ID="Chart1" runat="server" Width="1024px"> <Series> <asp:Series Name="销量"> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> </asp:ChartArea> </ChartAreas> <Legends> <asp:Legend Alignment="Center" Docking="Bottom" Name="Legend1" Title="销量分析"> </asp:Legend> </Legends> <Titles> <asp:Title Font="微软雅黑, 16pt" Name="Title1" Text="法国皇家龙船总体销售评估表"> </asp:Title> </Titles> </asp:Chart> </div>
后台 主要 源码:
/// <summary> /// 绑定报表控件数据源 /// </summary> public void BindData() { IList<Nop_Product> data = BindChartProduct(); #region 尚未用到 //ChartArea chartArea = SetChartAreaStyle("Chart1", true); //List<int> data = Models.StaticModel.createStaticData(); //System.Web.UI.DataVisualization.Charting.Chart Chart2 = new System.Web.UI.DataVisualization.Charting.Chart(); //Chart2.Width = 412; //Chart2.Height = 296; //Chart2.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.ImageTag; //Chart2.Palette = ChartColorPalette.BrightPastel; //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)); //Chart2.Titles.Add(t); //Chart2.ChartAreas.Add("Series 1"); // //Populate series with random data //Random random = new Random(); //for (int pointIndex = 0; pointIndex < 10; pointIndex++) //{ // Chart1.Series[0].Points.AddY(random.Next(45, 95)); // //Chart1.Series["Series2"].Points.AddY(random.Next(5, 75)); //} #endregion for (int i = 0; i < data.Count; i++) { Chart1.Series[0].Points.AddY(data[i].Quantity); } Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; Chart1.BorderlineWidth = 2; Chart1.BorderColor = System.Drawing.Color.Black; Chart1.BorderlineDashStyle = ChartDashStyle.Solid; Chart1.BorderWidth = 2; Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线 Chart1.ChartAreas["ChartArea1"].AxisY.Title = "销售数量(瓶)"; Chart1.ChartAreas["ChartArea1"].AxisX.Title = "时间(yyyy-MM)"; #region 尚未用到 //Chart1.Legends.Add("酒种类"); //Legend legend = new Legend(ddrTypeName.SelectedValue); //26, 59, 105 //legend.BackColor = Color.Transparent;//Color.FromArgb(26, 59, 105, 0); //legend.BorderColor = Color.Gray; //legend.Font = new System.Drawing.Font("Trebuchet MS", float.Parse("8.25"), FontStyle.Bold, GraphicsUnit.World); //legend.IsDockedInsideChartArea = true; //legend.DockedToChartArea = ddrTypeName.SelectedValue; //Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; //X轴数据显示间隔 //Chart1.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Days; //Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffset = 0.0; //Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffsetType = DateTimeIntervalType.Days; #endregion Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "yyyy年MM月"; Chart1.ChartAreas["ChartArea1"].AxisY.Interval = 20;//y轴数据显示间隔 Chart1.DataSource = data; Chart1.Series[0].YValueMembers = "Quantity"; Chart1.Series[0].XValueMember = "CreatedOn"; Chart1.DataBind(); // Set series chart type Chart1.Series[0].ChartType = SeriesChartType.Line; //Chart1.Series["Series2"].ChartType = SeriesChartType.Spline; // Set point labels Chart1.Series[0].IsValueShownAsLabel = true; //Chart1.Series["Series2"].IsValueShownAsLabel = true; // Enable X axis margin Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; // Enable 3D, and show data point marker lines Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false; Chart1.Series[0]["ShowMarkerLines"] = "True"; //Chart1.Series["Series2"]["ShowMarkerLines"] = "True";
效果图如下:
在此,只写出自己研究所得. 如有不当之处,希望大家多多指教,共同进步. 谢谢
相关文章推荐
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- ASP.NET中的MSChart 控件使用
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- OWA或Messenger样式的信息提示窗口——编写ASP.NET AJAX Extender控件(下):使用该控件(示例程序)
- ASP.NET WebForm 分页控件 AspNetPager 使用的简单示例
- ASP.NET 2.0使用FileUpload控件上传文件示例
- ASP.NET 2.0使用FileUpload控件上传文件示例
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- asp.net微软图表控件使用示例代码分享
- ASP.Net中数据展示控件的嵌套使用示例
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- ASP.NET3.5下的MSChart图表控件使用
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)
- Asp.net 2.0 自定义控件开发专题[详细探讨页面状态(视图状态和控件状态)机制及其使用场景](示例代码下载)