Thank u so much :)
On Thursday, September 25, 2014 4:48:56 AM UTC+5:30, Andrew Gallant wrote:
>
> You can build the grouping columns array in a loop:
>
> var groupColumns = [];
> for (var i = 0; i < noOfCustomers; i++) {
> groupColumns.push({ 'column': i + 1, 'aggregation':
> google.visualization.data.sum, 'type': 'number' });
> }
> result = google.visualization.data.group(data, [{ column: 0, modifier:
> getMonths, type: 'date'}], groupColumns);
>
> On Wednesday, September 24, 2014 1:43:42 AM UTC-4, Shivani Kanakhara wrote:
>>
>> I am generating a column chart where data is fetched using ajax on the
>> basis of customers selected. i.e. if customers A and B are selected then
>> the data fetched will be of type:
>> Date A B
>> 2014/12/13 23.4 43
>> 2014/12/12 33.5 33.5
>> 2014/01/23 33.4 55.6
>> 2014/01/12 112 45.6
>>
>> Similarly, if customers A B C D are selected the data fetched will be like
>> Date A B C D
>> 2014/12/13 23.4 43 22 334
>> 2014/12/12 33.5 33.5 33 44
>> 2014/01/23 33.4 55.6 55 54
>> 2014/01/12 112 45.6 33 33
>>
>> Now this data is then grouped on months and on clicking a button chart is
>> generated.
>>
>> Problem is that i have to write separate code for grouping for every
>> number of customers selected--
>>
>> if (noOfCustomers == 1) {
>> result = google.visualization.data.group(
>> data,
>> [{ column: 0, modifier: getMonths, type: 'date'}],
>> [{ 'column': 1, 'aggregation':
>> google.visualization.data.sum, 'type': 'number'}]
>> );
>> }
>> else if (noOfCustomers == 2) {
>> result = google.visualization.data.group(
>> data,
>> [{ column: 0, modifier: getMonths, type: 'date'}],
>> [{ 'column': 1, 'aggregation':
>> google.visualization.data.sum, 'type': 'number' }, { 'column': 2,
>> 'aggregation': google.visualization.data.sum, 'type': 'number'}]
>> );
>> }
>> else if (noOfCustomers == 3) {
>> result = google.visualization.data.group(
>> data,
>> [{ column: 0, modifier: getMonths, type: 'date'}],
>> [{ 'column': 1, 'aggregation':
>> google.visualization.data.sum, 'type': 'number' }, { 'column': 2,
>> 'aggregation': google.visualization.data.sum, 'type': 'number' }, {
>> 'column': 3, 'aggregation': google.visualization.data.sum, 'type':
>> 'number'}]
>> );
>> }
>> else if (noOfCustomers == 4) {
>> result = google.visualization.data.group(
>> data,
>> [{ column: 0, modifier: getMonths, type: 'date'}],
>> [{ 'column': 1, 'aggregation':
>> google.visualization.data.sum, 'type': 'number' }, { 'column': 2,
>> 'aggregation': google.visualization.data.sum, 'type': 'number' }, {
>> 'column': 3, 'aggregation': google.visualization.data.sum, 'type': 'number'
>> }, { 'column': 4, 'aggregation': google.visualization.data.sum, 'type':
>> 'number'}]
>> );
>> }
>>
>> return result;
>>
>> [{ 'column': 1, 'aggregation': google.visualization.data.sum, 'type':
>> 'number'}] only because of change in this piece of code i have to repeat
>> the entire code for data grouping.
>>
>> Is there a way where i can like use a loop where the code for grouping
>> will be generated according to noOfCustomers selected?
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.