PDA

View Full Version : Multiple groupings for charts



Brett89
12 Apr 2012, 10:51 PM
I have a data structure like this:




[
{
Month: 'January',
ID: 1,
Name: 'Foo',
Value: 1
},
{
Month: 'February',
ID: 1,
Name: 'Foo',
Value: 2
},
{
Month: 'March',
ID: 1,
Name: 'Foo',
Value: 3
},
{
Month: 'January',
ID: 2,
Name: 'Bar',
Value: 4
},
{
Month: 'February',
ID: 2,
Name: 'Bar',
Value: 5
},
{
Month: 'March',
ID: 2,
Name: 'Bar',
Value: 6
}
]



Is there a way to present a column chart that is grouped by both Month and ID? Currently, my solution is to change the data structure to be like this:




[
{
Month: 'January',
'Value-1': 1,
'Value-2': 4
},
{
Month: 'February',
'Value-1': 2,
'Value-2': 5
},
{
Month: 'March',
'Value-1': 3,
'Value-2': 6
}
]



And then on store load I'm doing some hacky stuff to change the model's fields, because the number of "Value-x" properties is dynamic. I'm also extracting the ID from "Value-x". The whole thing is just really hacky, and I get the feeling that there is a better way to do this in Ext. Any help would be greatly appreciated.

mitchellsimoens
13 Apr 2012, 7:57 AM
What kind of chart are you using? You can use the 2nd data but you will need to know the fields up front to create the chart.

Brett89
15 Apr 2012, 5:20 PM
Thanks for your reply. I'm presenting this data in a column chart (bottom axis: Month; left axis: Value). I currently have it working using the second data structure I provided, but my question is "Is it possible to use the first data structure?". In order to do this, there would need to be some method of grouping on multiple fields. Something like this:



...
axes: [
{
title: 'Value',
type: 'Numeric',
position: 'left',
fields: 'Value'
},
{
type: 'Category',
position: 'bottom',
fields: ['Month', 'ID']
}
],
...