ASP.Net MVC 3

Sep 5, 2011 at 2:38 PM

Hi 

Do you have any example or suggestions how to define highcharts.net library in an ASP.Net MVC3 controller returning json values?

Here is my controller

  public ActionResult HighChart()
        {
           // Defining Axis
            Highchart.UI.LineChart hcVendas = new Highchart.UI.LineChart();
            hcVendas.YAxis = new YAxis { title = new Title("Faturamento") };
            hcVendas.XAxis = new XAxis { categories = new[] { "1994""1995""1996""1997""1998""1999""2000""2001""2002" } };
            //hcVendas.RenderControl("container");
            //New data collection
            var series = new Collection<Serie>();
            series.Add(new Serie { data = new object[] { 400, 435, 446, 479, 554, 634, 687, 750, 831 } });
 
            //bind
            hcVendas.DataSource = series;
            hcVendas.DataBind();
            return Json(hcVendas, JsonRequestBehavior.AllowGet);
            //return View("HighChart");
        }

here is my view

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>HighChart</h2>
   <div id="container"> </div>
   <highchart:LineChart id="hcVendas" runat="server" Width="500" Height="350" /> 
</asp:Content>

Chart is not renedered though data and chart definitions are returned from the contoller?
Regards
Ajay
Developer
Nov 20, 2011 at 8:31 AM
Edited Nov 20, 2011 at 9:22 AM

I know this is quite late but most likely, the problem is that the data is being bound to the Highchart control too late in the page lifecycle. Similar to the problem faced by faris_rjoup here [highcharts.codeplex.com].

I don't have a sample project on which to test this out, but the solution at the bottom of the page could also help with the problem for an MVC project.