ASP.NET MVC 2 上的 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论