This is a migrated thread and some comments may be shown as answers.

LIne chart and custom JSON

3 Answers 36 Views
Charts
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 23 Sep 2015, 02:36 PM

I have this JSON:

[{ ​Name: "A", Data: [1, 2, 3]}, { Name: "B", Data: [3, 4, 1]}]

Is there a way to tell the Line Chart that the name field is "Name" and field is "Data"?  I have tried Series.Field and Series.CategoryField and it doesn't work.  

 If you try the dojo JS page from the demo and just change "name" to "Name" and "data" to "Data", it will break.  Setting the field value in the seriesDefault will not work.  Is the lowercase value hard coded for line charts because for others like pie charts, it works just fine.

 Thanks.

3 Answers, 1 is accepted

Sort by
0
EZ
Top achievements
Rank 2
answered on 24 Sep 2015, 02:06 PM

 

var datajson = [{ Name: "A", Data: [1, 2, 3]}, { Name: "B", Data: [3, 4, 1]}];
      

<p>var series = [];<br> for (var i=0; i<datajson.length; i++){<br>        var s = { data: datajson[i].Data, name: datajson[i].Name };<br>        series.push(s);<br>}​</p><p> </p><p>$("#chart").kendoChart({<br>                legend: {<br>                    visible: true<br>                },<br>                seriesDefaults: {<br>                    type: "line",<br>                },<br>                series: series<br> });​</p>
var series = [];
for (var i=0; i<datajson.length; i++){
        var s = { data: datajson[i].Data, name: datajson[i].Name };
        series.push(s);
}​

 

$("#chart").kendoChart({
                legend: {
                    visible: true
                },
                seriesDefaults: {
                    type: "line",
                },
                series: series
});​

 

Here is a DEMO

0
David
Top achievements
Rank 1
answered on 25 Sep 2015, 12:34 AM

You are taking the JSON and pushing it into another JSON array with the lower case name which is not the point.  I'm trying to avoid all that by telling Kendo charts that the fields are "Name" and "Data".

I'm guessing that's not possible as suspected.

0
T. Tsonev
Telerik team
answered on 25 Sep 2015, 02:02 PM
Hi,

This particular setup is not supported. Per-series data arrays can be passed through configuration only and it is case-sensitive.

In data-bound mode, the data item fields can be arbitrary. In this case series are bound to individual fields on the data items. See Data Binding.

The alternative that EZ suggests is fine. The resulting series will be valid, configuration wise.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Charts
Asked by
David
Top achievements
Rank 1
Answers by
EZ
Top achievements
Rank 2
David
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or