Preston
Preston

Reputation: 1346

Using ASP.NET Charts in MVC

I am able to build charts in MVC like below however the problem is I can't add colors, and do a lot of the fancy things that can be done in the ASP.NET chart control. Is there a way to do that with this Chart type or an alternative to doing this in MVC.

public ActionResult GetRainfallChart()
{

    var key = new Chart(width: 600, height: 400)
        .AddSeries(
            chartType: "bar",
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
            yValues: new[] { "40", "10", "20", "20", "10" })
        .AddTitle("Title")
        .Write();


    return null;
}

Upvotes: 2

Views: 780

Answers (1)

nkvu
nkvu

Reputation: 5821

If you want to use the ASP.NET chart control then perhaps you can add a Web Forms page (or pages as per your app design etc) to your project. Web Forms and MVC should be able to co-exist and there should be quite a few blog posts, SO questions etc around it too. It may also be possible to have a Web Forms control on the same page but I have never tried it myself so can't comment 100%.

The alternative may be to use a JavaScript based graphing library like flot (http://www.flotcharts.org/). So what you would do there is something like:

  1. Have your controller gather (or coordinate the gathering of) all the appropriate data for the graph
  2. Render or otherwise place the data into your view
  3. Render using flot (flot also requires JQuery but that shouldn't be a problem)

I just mention flot because it's one I know about; my personal experience is that it can be a little hard to get into so YMMV.

HTH though, Nathan.

Upvotes: 1

Related Questions