0

I need to include a chart generated with ChartJS in an Asp.Net view into a report created using Report Viewer in C# Asp.Net MVC. To do that, i thought about to run the view in memory (without open in a browser) and save the canvas where the chart is into an image file. So, i would use this file into the report.

How can I do that? If it's not possible to run a view in memory, is there any other way to accomplish what I need.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • 1
    You can execute a controller action and get the resulting HTML in memory, but it won't render the HTML and it certainly won't execute any javascript unless you load it in a browser. https://stackoverflow.com/questions/483091/how-to-render-an-asp-net-mvc-view-as-a-string – Paul Abbott Jul 31 '18 at 22:28
  • I've run out of votes for the day, but Paul's comment above is completely right. If you don't run it in a browser, there's no JavaScript context, so there won't be any canvas to export from. I suggest instead you use the same source data to produce a similar-looking chart using a .NET component (there's a microsoft charting component freely available, for instance) and insert that into your report instead. Or alternatively, find a client-side way of writing your reports so you can incorporate things from your client-side chart into it. – ADyson Jul 31 '18 at 23:03
  • Well, makes total sense! I was so desesperated to acomplish what i need that i didn't thought about the basic need of a browser to render the view and execute the JS. Thanks a lot for drive me back to the reality! And my apologies for wasting your time with such a question. – Miron Alighieri Aug 02 '18 at 16:50

0 Answers0