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

Stack and Grouped not grouping correctly

2 Answers 46 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Nick Jones
Top achievements
Rank 1
Nick Jones asked on 25 Mar 2014, 11:46 AM
Ok... frustratingly this is the second time I'm writing this as the first post failed for some reason.

I know there is a similar post to this here, http://www.telerik.com/forums/stacked-column-chart-where-group-is-a-property but the example code looks nothing like the api documentation, so hopefully someone can explain what's wrong with mine.  The grouping is missing the first day completely!

Json looks like:
[{"tdate": "2014-03-18T00:00:00", "data": 652.48 , "CatName": "Starters"},{"tdate": "2014-03-18T00:00:00", "data": 1245.87 , "CatName": "Spirits"},{"tdate": "2014-03-21T00:00:00", "data": 326.55 , "CatName": "Beers"},{"tdate": "2014-03-22T00:00:00", "data": 124.28 , "CatName": "Beers"},{"tdate": "2014-03-24T00:00:00", "data": 785.24 , "CatName": "Starters"},{"tdate": "2014-03-24T00:00:00", "data": 444.74 , "CatName": "Beers"},{"tdate": "2014-03-24T00:00:00", "data": 345.54 , "CatName": "Spirits"}]

HTML
<div id="chart"></div>

Script:
var myTheme = 'metro';

var myds = $('#MainContent_hdn1').val();
var jsondata = $.parseJSON(myds);

var mydatasource = new kendo.data.DataSource({
group: [
{ field: "CatName" }
],
sort: { field: "tdate", dir: "asc" },
data: jsondata
});

$("#chart").kendoChart({
dataSource: mydatasource,
series: [{
field: "data"
}],
group: { field: "CatName" },
categoryAxis: {
field: "tdate",
baseUnit: 'day',
type: 'date',
majorGridLines: {
visible: false
},
line: {
visible: false
}
},
seriesDefaults: {
stack: true
},
chartArea: {
height: 250
},
theme: myTheme,
tooltip: {
visible: true,
template: "#= series.name #: #= value #"
}
});

Output looks like attached pic.

2 Answers, 1 is accepted

Sort by
0
Nick Jones
Top achievements
Rank 1
answered on 25 Mar 2014, 03:34 PM
Further to the above post.  I've replaced the data in telerik's example with my data and still it's not grouping the data correctly.  Can anyone suggest why the datasource isn't grouping?  Example here, http://jsbin.com/kizuy/13/edit
0
Iliana Dyankova
Telerik team
answered on 25 Mar 2014, 04:21 PM
Hello Nick,

I already posted a reply in your other thread, however I am pasting my answer here too:

The observed behaviour is due to the different number of data points in the groups. As an explanation: 
- By design categorical charts require a matching set of data points;
- The categories in a grouped chart are created depending on the first group.

In case there is a different number of values you need to use series.categoryField instead ofcategoryAxis.field. For your convenience I updated the jsBin example - please check it and let me know if this information helps or in case I can assist you further. Wish you a great day!

On a side note, please refrain from posting duplicate tickets as we monitor all threads - posting same question more than once produces unnecessary overload.

Regards,
Iliana Nikolova
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Charts
Asked by
Nick Jones
Top achievements
Rank 1
Answers by
Nick Jones
Top achievements
Rank 1
Iliana Dyankova
Telerik team
Share this question
or