Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Charting in MVC 4

I have been searching for quite a while and have not been able to find what I am looking for.

I want to generate a chart in my controller and serve it to my view via a ViewModel. The two most useful articles I found are

http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx#tb

Charting in ASP.Net MVC 3

Both show you how to create the chart object, but they don't help me display it in the view in a way I desire. I understand you can save the image and simply open the image from your view, but what if I desire the chart to be interactive? Perhaps going to a another page when clicking a slice on a pie chart, or other useful "drill down" functionality.

Am I confused? Is this sort of functionality possible with pure asp.net mvc, or am I confusing the fancy features with a 3rd party charting library? If the former, how do I render my chart object public Chart queueChart { get; set; } in my view?

And just as a note, I am not interested in using a 3rd party charting library.

Controller:

//Query from db into model.queue
Chart chart = new Chart();
chart.Width = 600;
chart.Height = 400;
chart.Titles.Add("Title goes here");
chart.ChartAreas.Add(new ChartArea());
Series series = new Series();

series.ChartType = SeriesChartType.Pie;

foreach( Queue i in model.queue )
{
    string x = i.name;
    double y = i.count;

    series.Points.AddXY(x, y);
}

chart.Series.Add(series);

model.queueChart = chart;
like image 718
Jeff Avatar asked Dec 26 '22 13:12

Jeff


1 Answers

Why not use a JavaScript library that does charting? These will offer lots of functionality and allow you to have interactive charts.

HighCharts

KendoUI

like image 103
Cloud SME Avatar answered Jan 08 '23 17:01

Cloud SME