ASP.NET MVC 2上的MSChart

时间:2010-04-14 15:29:47

标签: asp.net-mvc mschart

我使用MSChart将我的MVC应用程序升级到MVC 2,最终导致图表的图像链接损坏。

我不再遇到构建错误,并完成了以下步骤。

首先,我设置了以下web.config行。

add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" 
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35"

add path="ChartImg.axd" verb="GET,HEAD" 
type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, 
System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=31bf3856ad364e35" validate="false"

(注意:我关闭了V形符号,这样就显示了这些线条)

我接下来要做的是使用以下代码创建此页面。根据它在MVC< 1中的工作,它应该显示4个图表。

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="Scorecard.Views" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Scorecard
</asp:Content>

<asp:Content ID="applicationTitle" ContentPlaceHolderID="ContentPlaceHolderApplicationName" runat="server">
    <%=Html.Encode(ViewData["ApplicationTitle"])%>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="form1" runat="server">

<h2>
    Web Analysis Scorecard
</h2>

<table>
    <tr>
        <td>
            <%
                ChartHelper chartHelper = new ChartHelper("Top Countries",
                                                          (double[])ViewData["TopCountryCounts"],
                                                          (string[])ViewData["TopCountries"],
                                                        SeriesChartType.Pie);
                Chart chartPieTwo = chartHelper.ResultingChart;

                // Explode data point with label "USA"
                chartPieTwo.Series["DefaultSeries"].Points[3]["Exploded"] = "true";

                chartHelper.RenderChart(this);
            %>
        </td>
        <td>
            <%
                chartHelper = new ChartHelper("View Cart Trend",
                                              (double[])ViewData["LineValues"],
                                              (string[])ViewData["TopEngines"],
                                              SeriesChartType.Line);
                chartHelper.RenderChart(this);
            %>
        </td>
    </tr>
    <tr>
        <td>
            <%  chartHelper = new ChartHelper("Yesterday's Page Views",
                          (double[])ViewData["ColumnStats"],
                          (string[])ViewData["ColumnStatHeaders"],
                          SeriesChartType.Column);
                chartHelper.RenderChart(this);
            %>
        </td>
        <td>
            <%
                double[] theValues = (double[])ViewData["ColumnStats"];
                double[] newValues = new double[] { 0, 0, 0, 0 };
                int count = 0;
                int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                foreach (double d in theValues)
                {
                    newValues[count] += d * daysInMonth;
                    count++;
                }

                chartHelper = new ChartHelper("Current Month Page Views",
                                              newValues,
                                              (string[])ViewData["ColumnStatHeaders"],
                                              SeriesChartType.Bar);
                chartHelper.RenderChart(this);
            %>
        </td>
    </tr>
</table>
</form>

我还在这里发布了一个博客文章:http://blog.adronbhall.com/post/2010/04/12/MVC-2-Breaks-my-Charts.aspx

0 个答案:

没有答案