微软去年11月发布了一个很酷的新ASP.NET服务器控件,<asp:chart />,可以免费用在ASP.NET 3.5中,而且还可以用在asp.net mvc。可以看新ASP.NET图表控件<asp:chart runat="server"/>。
相关资源的下载链接:
Download the free Microsoft Chart Controls Download the VS 2008 Tool Support for the Chart Controls Download the Microsoft Chart Controls Samples Download the Microsoft Chart Controls Documentation这位台胞的两篇相当不错的文章
Microsoft Chart Controls 心得(1)
Microsoft Chart Controls 心得(2) - 如何透過圖表傳值
园子里的相关文章:
ASP.NET图表控件
我今天才知道ASP.NET图表控件发布了,附一个在线文档
在这里有一篇文章简短介绍了Combining ASP.NET MVC and ASP.NET Charting Controls.
编辑Web.Config
将控件的命名空间加到 (path: "<system.web><pages><controls>") :
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
添加一个 httpHandler ("<httpHandlers>"下面) :
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
将chart 控件添加到view
<p>
<%
System.Web.UI.DataVisualization.Charting.Chart Chart2 = new System.Web.UI.DataVisualization.Charting.Chart();
Chart2.Width = 412;
Chart2.Height = 296;
Chart2.RenderType = RenderType.ImageTag;
Chart2.Palette = ChartColorPalette.BrightPastel;
Title t = new Title("No Code Behind Page", 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");
// create a couple of series
Chart2.Series.Add("Series 1");
Chart2.Series.Add("Series 2");
// add points to series 1
foreach (int value in (List<int>)ViewData["Chart"])
{
Chart2.Series["Series 1"].Points.AddY(value);
}
// add points to series 2
foreach (int value in (List<int>)ViewData["Chart"])
{
Chart2.Series["Series 2"].Points.AddY(value + 1);
}
Chart2.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart2.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
Chart2.BorderlineDashStyle = ChartDashStyle.Solid;
Chart2.BorderWidth = 2;
Chart2.Legends.Add("Legend1");
// Render chart control
Chart2.Page = this;
HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output);
Chart2.RenderControl(writer);
%>
</p>
效果如下:
本文代码基于asp.net mvc rc版本:MVCCharting
Streaming Chart Images as FileResult from MVC Controllers : http://www.codeproject.com/KB/aspnet/MvcChartControlFileResult.aspx
用 ASP.NET 和 LINQ 图表的终极 ASP.NET :http://msdn.microsoft.com/zh-cn/magazine/dd453008.aspx