ASP.NET MVC 2 上的 MSChart

发布于 2024-08-28 11:44:48 字数 3959 浏览 4 评论 0原文

我使用 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

I upgraded my MVC Application using MSChart to MVC 2 and have ended up with broken image links for the charts.

I get no build errors anymore, and have completed the following steps.

First, I setup the following web.config lines.

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

and

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"

(NOTE: I took the chevrons off so the lines would appear)

The next thing I did was create this page with the following code. Which should, according to it working in MVC<1, showed 4 charts.

<%@ 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>

I also posted a blog entry here: http://blog.adronbhall.com/post/2010/04/12/MVC-2-Breaks-my-Charts.aspx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文