2

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;
}
1
  • 1
    Use built-in javascript chart plugins. I believe there are many Jquery plugins for it. As for information, Webform is less likely to hold onto javascript than MVC. You will using javascript more in MVC due to its response-request pattern Commented Mar 21, 2013 at 1:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.