微軟去年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圖表控制項發布了,附一個線上文檔
.NET MSChart應用的一個簡單例子
告別.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 seriesChart2.Series.Add("Series 1");Chart2.Series.Add("Series 2");// add points to series 1foreach (int value in (List<int>)ViewData["Chart"]){Chart2.Series["Series 1"].Points.AddY(value);}// add points to series 2foreach (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 controlChart2.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