新的asp.net图表控件-它们最终将与MVC一起使用吗?

Scott Gu刚发布了有关.NET团队分发的一组新的图表控件。它们看起来令人难以置信:http : //weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt。 aspx


一百万美元的问题是……他们将与MVC合作吗?


慕虎7371278
浏览 473回答 3
3回答

倚天杖

您可以通过两种方式使用图表控件:从控制器生成图像通过生成图表并将其作为操作返回的图像(如查图曼所说,我认为):Chart chart = new Chart();chart.BackColor = Color.Transparent;chart.Width = Unit.Pixel(250);chart.Height = Unit.Pixel(100);Series series1 = new Series("Series1");series1.ChartArea = "ca1";series1.ChartType = SeriesChartType.Pie;series1.Font = new Font("Verdana", 8.25f, FontStyle.Regular);series1.Points.Add(new DataPoint {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AxisLabel = "Value1", YValues = new double[] { value1 } });series1.Points.Add(new DataPoint {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AxisLabel = "Value2", YValues = new double[] { value2 } });chart.Series.Add(series1);ChartArea ca1 = new ChartArea("ca1");ca1.BackColor = Color.Transparent;chart.ChartAreas.Add(ca1);using (var ms = new MemoryStream()){&nbsp; &nbsp; chart.SaveImage(ms, ChartImageFormat.Png);&nbsp; &nbsp; ms.Seek(0, SeekOrigin.Begin);&nbsp; &nbsp; return File(ms.ToArray(), "image/png", "mychart.png");}WebForms样式这样,您只需将图表包括在.aspx视图中(就像使用传统的Web表单一样)。为此,您必须连接web.config中的相关位<controls>&nbsp; &nbsp; ...&nbsp; &nbsp; <add tagPrefix="asp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;namespace="System.Web.UI.DataVisualization.Charting"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></controls><httpHandlers>&nbsp; &nbsp; ...&nbsp; &nbsp; <add path="ChartImg.axd"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verb="GET,HEAD"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;validate="false"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></httpHandlers><handlers>&nbsp; &nbsp; ...&nbsp; &nbsp; <add name="ChartImageHandler"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;preCondition="integratedMode"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verb="GET,HEAD"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;path="ChartImg.axd"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/></handlers>构建图表时,无法在DataPoint元素内运行代码,因此要连接数据,需要在View类中使用一个方法。这对我来说很好。以这种方式工作可使控件呈现由图表控件http处理程序生成的图像的URL。在部署中,您需要为其提供一个可写文件夹以缓存图像。* VS 2010 / .NET 4支持*为了在.NET 4中正常工作,您需要使用适当的公钥令牌将图表引用更改为版本4.0.0.0。同样,图表控件现在可以生成指向当前请求路径而不是请求路由的url。对我来说,这意味着所有图表请求均导致404错误,因为/{Controller}/ChartImg.axd等价物被路线阻止了。为了解决这个问题,我添加了额外的IgnoreRoute调用来覆盖我的用法-一个更通用的解决方案会更好:public static void RegisterRoutes(RouteCollection routes){&nbsp; &nbsp; routes.IgnoreRoute("ChartImg.axd/{*pathInfo}");&nbsp; &nbsp; routes.IgnoreRoute("{controller}/ChartImg.axd/{*pathInfo}");&nbsp; &nbsp; routes.IgnoreRoute("{controller}/{action}/ChartImg.axd/{*pathInfo}");...
打开App,查看更多内容
随时随地看视频慕课网APP