MVC中图表控件如何在ASP.NET中使用-创新互联

MVC中图表控件如何在ASP.NET中使用?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

新干网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站等网站项目制作,到程序开发,运营维护。创新互联公司公司2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司

首先定义一个controller,提供以下方法实现


#region Chart Component 

public FileResult CreateChart(SeriesChartType chartType) 
{ 
IList peoples = _resultService.GetResults(); 
Chart chart = new Chart(); 
chart.Width = 700; 
chart.Height = 300; 
chart.BackColor = Color.FromArgb(211, 223, 240); 
chart.BorderlineDashStyle = ChartDashStyle.Solid; 
chart.BackSecondaryColor = Color.White; 
chart.BackGradientStyle = GradientStyle.TopBottom; 
chart.BorderlineWidth = 1; 
chart.Palette = ChartColorPalette.BrightPastel; 
chart.BorderlineColor = Color.FromArgb(26, 59, 105); 
chart.RenderType = RenderType.BinaryStreaming; 
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; 
chart.AntiAliasing = AntiAliasingStyles.All; 
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal; 
chart.Titles.Add(CreateTitle()); 
chart.Legends.Add(CreateLegend()); 
chart.Series.Add(CreateSeries(peoples,chartType)); 
chart.ChartAreas.Add(CreateChartArea()); 

MemoryStream ms = new MemoryStream(); 
chart.SaveImage(ms); 
return File(ms.GetBuffer(), @"image/png"); 
} 

[NonAction] 
public Title CreateTitle() 
{ 
Title title = new Title(); 
title.Text = "Result Chart"; 
title.ShadowColor = Color.FromArgb(32, 0, 0, 0); 
title.Font = new Font("Trebuchet MS", 14F, FontStyle.Bold); 
title.ShadowOffset = 3; 
title.ForeColor = Color.FromArgb(26, 59, 105); 

return title; 
} 

[NonAction] 
public Legend CreateLegend() 
{ 
Legend legend = new Legend(); 
legend.Name = "Result Chart"; 
legend.Docking = Docking.Bottom; 
legend.Alignment = StringAlignment.Center; 
legend.BackColor = Color.Transparent; 
legend.Font = new Font(new FontFamily("Trebuchet MS"), 9); 
legend.LegendStyle = LegendStyle.Row; 

return legend; 
} 

[NonAction] 
public Series CreateSeries(IList results, SeriesChartType chartType) 
{ 
Series seriesDetail = new Series(); 
seriesDetail.Name = "Result Chart"; 
seriesDetail.IsValueShownAsLabel = false; 
seriesDetail.Color = Color.FromArgb(198, 99, 99); 
seriesDetail.ChartType = chartType; 
seriesDetail.BorderWidth = 2; 
seriesDetail["DrawingStyle"] = "Cylinder"; 
seriesDetail["PieDrawingStyle"] = "SoftEdge"; 
DataPoint point; 

foreach (ResultModel result in results) 
{ 
point = new DataPoint(); 
point.AxisLabel =result.ID; 
point.YValues = new double[] {double.Parse(result.GPA) }; 
seriesDetail.Points.Add(point); 
} 
seriesDetail.ChartArea = "Result Chart"; 

return seriesDetail; 
} 

[NonAction] 
public ChartArea CreateChartArea() 
{ 
ChartArea chartArea = new ChartArea(); 
chartArea.Name = "Result Chart"; 
chartArea.BackColor = Color.Transparent; 
chartArea.AxisX.IsLabelAutoFit = false; 
chartArea.AxisY.IsLabelAutoFit = false; 
chartArea.AxisX.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F, FontStyle.Regular); 
chartArea.AxisY.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F, FontStyle.Regular); 
chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64); 
chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64); 
chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64); 
chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64); 
chartArea.AxisX.Interval = 1; 

return chartArea; 
} 

#endregion

图表类的各种属性,可以控制宽度,高度,边框颜色,背景颜色,皮肤,调色板,等。最终形成图片格式展现在页面。

这里介绍的项目是ASP.NET MVC的图表控件的一个小demo示例,最终展示如下:

MVC中图表控件如何在ASP.NET中使用

看完上述内容,你们掌握 MVC中图表控件如何在ASP.NET中使用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网站标题:MVC中图表控件如何在ASP.NET中使用-创新互联
链接分享:http://bzwzjz.com/article/dessii.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 古蔺网站建设 专业网站设计 成都网站设计 网站建设公司 阿坝网站设计 营销型网站建设 成都网站制作 成都定制网站建设 手机网站制作设计 重庆手机网站建设 成都网站设计 成都网站制作 成都网站建设 网站制作 成都网站设计 成都网站设计 自适应网站建设 高端网站设计 成都网站建设公司 四川成都网站设计 成都网站建设公司 成都网站制作