在asp.net mvc上应用新ASP.NET图表控件

来源:互联网 发布:thinkphp三级分销源码 编辑:程序博客网 时间:2024/06/01 09:05

微软去年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>
    效果如下:
    mschartmvc 
    本文代码基于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
    .csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }