Answered by:
Is this usable in ASP.Net MVC framework?

Question
-
Is there a way one can use this in ASP.Net MVC framework? (as standard asp.net controls are not usable in mvc framework for its dependency on viewstate.Thursday, November 6, 2008 1:28 PM
Answers
-
I never tried MS chart control in ASP.NET MVC framework. You can use the control just to generate chart images without using any of ASP.NET control specific functionality. You can create an instance of the control, add all chart elements (Titles, Legends, Series, DataPoint, ...) and then call SaveAsImage method to get chart image. I will be very interested to find out the results of your experiment and help with any issues that you may find.
Alex.- Proposed as answer by Alex GorevMicrosoft employee Thursday, November 6, 2008 10:40 PM
- Marked as answer by Ajay Navgale Friday, November 7, 2008 10:10 AM
Thursday, November 6, 2008 3:54 PM
All replies
-
I never tried MS chart control in ASP.NET MVC framework. You can use the control just to generate chart images without using any of ASP.NET control specific functionality. You can create an instance of the control, add all chart elements (Titles, Legends, Series, DataPoint, ...) and then call SaveAsImage method to get chart image. I will be very interested to find out the results of your experiment and help with any issues that you may find.
Alex.- Proposed as answer by Alex GorevMicrosoft employee Thursday, November 6, 2008 10:40 PM
- Marked as answer by Ajay Navgale Friday, November 7, 2008 10:10 AM
Thursday, November 6, 2008 3:54 PM -
Thanks Alex. I will use it in my MVC project and will update you with the result. Thanks again.Friday, November 7, 2008 10:11 AM
-
One example of how to use the controls can be found here here
It shows how to render the charts using a httphandler.Friday, November 14, 2008 12:43 PM -
I am working on the charting in ASP.NET with MVC4. I took the same approach as you describe above. I am return and image in png format from controller method. But I am facing a problem here to make availability of tool-tip on hover on any data-point. If you have something relevant to my problem please advice.
Thanks
Love to c#
Thursday, March 5, 2015 6:31 AM -
Hi,
i have a little Html-Helper method for this:
public static MvcHtmlString Chart(this HtmlHelper htmlHelper, Chart chart) { if (chart == null) return MvcHtmlString.Empty; var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { using (var writer = new HtmlTextWriter(sw)) { chart.RenderControl(writer); return MvcHtmlString.Create(sb.ToString()); } } }
And in the view:
@model Models.ChartViewModel <div> @Html.Chart(Model.Chart) </div>
The viewmodel has only the Chart property with System.Web.UI.DataVisualization.Charting.Chart as type and the chart is generated within a controller action.
You need also ignore some routes:
routes.IgnoreRoute("{controller}/ChartImg.axd"); routes.IgnoreRoute("{controller}/{action}/ChartImg.axd");
and update web.config:
<appSettings> <add key="ChartImageHandler" value="storage=file;timeout=20;URL=/App_Data/MicrosoftChartControls/" /> </appSettings> <system.webServer> <remove name="ChartImageHandler" /> <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </handlers> </system.webServer>
- Edited by SaschaM Friday, March 20, 2015 1:10 PM
Friday, March 20, 2015 1:04 PM