Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I update a KendoUI chart via javascript JSON?
    primarykey
    data
    text
    <p>So I have a chart which is configured using the MVC style configuration...</p> <pre><code>@(Html.Kendo().Chart&lt;DIMVC.ViewModel.CompanyProduction&gt;(Model.CompanyProduction) .Name("Chart") .Title("Files sent") .Legend(legend =&gt; legend .Position(ChartLegendPosition.Bottom) ) .ChartArea(chartArea =&gt; chartArea .Background("transparent") ) .SeriesDefaults(seriesDefaults =&gt; seriesDefaults.Line().Style(ChartLineStyle.Smooth) ) .Series(series =&gt; { series.Line(model =&gt; model.SentFiles).Name("Sent Files"); ... { lots more series added here } } .CategoryAxis(axis =&gt; axis .Categories(model =&gt; model.MonthDisplay) .Labels(labels =&gt; labels.Rotation(-90)) ) .ValueAxis(axis =&gt; axis.Numeric() .Labels(labels =&gt; labels.Format("{0:N0}")) .MajorUnit(10000) ) .Tooltip(tooltip =&gt; tooltip .Visible(true) .Format("{0:N0}") ) .Events(e =&gt; e .SeriesClick("onSeriesClick") ) </code></pre> <p>)</p> <p>I also have a slider on the page. When the slider value is changed I handle this event.</p> <pre><code>@(Html.Kendo().RangeSlider() .Name("yearRange") .Min(2000) .Max(DateTime.Today.Year) .SmallStep(1) .LargeStep(5) .Values(Model.MinYear, Model.MaxYear) .Events(e =&gt; e.Change("yearRangeChange")) ) </code></pre> <p><em><strong>javascript method</em></strong></p> <pre><code>function yearRangeChange(e) { var url = "/FetchData/"; $.ajax({ type: "GET", url: url, data: { startYear: e.values[0], endYear: e.values[1] }, dataType: "json", success: function (json) { $("#DINETChart").kendoChart({ dataSource: { data: json } }); var chart = $("#DINETChart").data("kendoChart"); chart.refresh(); } }); } </code></pre> <p>now when the chart is updated the grid is just blank.</p> <p>The json request is successfully called and the data is retrieved. but after the chart is populated the chart is blank.</p> <p>has anyone got any suggestions?</p> <p><strong>* EDIT *</strong></p> <p>adding a sample of the JSON returned</p> <p><code>"[{\"CompanyID\":1,\"Year\":2011,\"Month\":8,\"SentFiles\":1666,\"ReceivedFiles\":1632,\"SentData\":12803.674593292486,\"ReceivedData\":11908.047586546765,\"Note\":null,\"MonthDisplay\":\"Aug\",\"CompanyDisplay\":null},{\"CompanyID\":1,\"Year\":2013,\"Month\":10,\"SentFiles\":21004,\"ReceivedFiles\":20387,\"SentData\":157376.825542573,\"ReceivedData\":152878.87845794103,\"Note\":null,\"MonthDisplay\":\"Oct\",\"CompanyDisplay\":null},{\"CompanyID\":1,\"Year\":2013,\"Month\":4,\"SentFiles\":9989,\"ReceivedFiles\":9880,\"SentData\":74913.53277995327,\"ReceivedData\":75145.16331588416,\"Note\":null,\"MonthDisplay\":\"Apr\",\"CompanyDisplay\":null},{\"CompanyID\":1,\"Year\":2013,\"Month\":11,\"SentFiles\":25956,\"ReceivedFiles\":25249,\"SentData\":196155.8977337967,\"ReceivedData\":189320.44546897494,\"Note\":null,\"MonthDisplay\":\"Nov\",\"CompanyDisplay\":null}]"</code></p> <p>I would also like to point out that if I add this</p> <pre><code>.DataSource(ds =&gt; ds.Read(read =&gt; read.Action("FetchData", "Home", new { startYear = 2012, endYear = 2013 }) )) </code></pre> <p>to my chart configuration, this will populate the chart fine, without using the page <code>Model</code>. i.e. The data is correct for the chart.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload