How to use chart management in mvc

I want to use Chart in my MVC panel form.

I used the following code.

@{ var key = new Chart(width: 300, height: 300) .AddTitle("Employee Chart") .AddSeries( chartType: "Bubble", name: "Employee", xValue: new[] { "Peter", "Andrew", "Julie", "Dave" }, yValues: new[] { "2", "7", "5", "3" }); } <!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> <div> <div> @key.Write() </div> </div> </body> </html> 

but @key.Write() writes the diagram on the whole page, but I want it to be in partial form not in full form with other content on the Dashboard page. Can anyone help me on this. Thanks at Advanced.

+4
source share
1 answer

Move your chart code to the controller action as follows:

  public ActionResult GetChartImage() { var key = new Chart(width: 300, height: 300) .AddTitle("Employee Chart") .AddSeries( chartType: "Bubble", name: "Employee", xValue: new[] { "Peter", "Andrew", "Julie", "Dave" }, yValues: new[] { "2", "7", "5", "3" }); return File(key.ToWebImage().GetBytes(), "image/jpeg"); } 

(enable the use of the System.Web.Helpers namespace) and change your view:

 <!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> <div> <div> <img src="@Url.Action("GetChartImage")" /> </div> </div> </body> </html> 
+5
source

All Articles