Hi again :=)
Yes it gives me the sum, the way u suggested.
As expected below code gives me the sum for 5 columns as a 1 row table. So,
when this all is rendered in a jsp,it gives me table 1 with all rows and
below that table 2 with summed data for above table. This table 2 has same
column labels as table1, which is an issue, bcoz i just want to display the
sum for each column. Is there any way to correct that ( ijust need the row
for that table and not the headers).
Also i am not able to format the cells for this table. Is it some thing
like setProperty() doesn't work for grouped data?
Here i the code snippet:**
*
var grouped_data = google.visualization.data.group(data, [{
column: 0,type:'string',modifier:
function () {
var modifiedString="A";
return modifiedString;
}
}], [
{column: 1, type: 'number',aggregation: google.visualization.data.sum},
{column: 2, type: 'number',aggregation: google.visualization.data.sum},
{column: 3, type: 'number',aggregation: google.visualization.data.sum},
{column: 4, type: 'number',aggregation: google.visualization.data.sum},
{column: 5, type: 'number',aggregation: google.visualization.data.sum}
]);
grouped_data.setProperty(0, 1, "style","text-align: center;");
var groupedView = new google.visualization.DataView(grouped_data);
groupedView.setColumns([1,2,3,4,5]);
var sumChart = new
google.visualization.Table(document.getElementById('summedData'));
sumChart.draw(groupedView);
*
On Thursday, November 29, 2012 12:24:15 PM UTC+5:30, asgallant wrote:
> You can use the group function to get the sum of a column, you just likely
> need to use a modifier function on another column in the table to make all
> of the values to group by uniform.
>
> var group = google.visualization.data.group(data, [{
> column: 0, // pick something other than a column you need summed
> type: 'number',
> modifier: function () {
> // make all values the same
> return 0;
> }
> }], [{
> // you can repeat this object as many times as you like to get the
> sum of each column that you need
> column: 1, // use the index of the column to sum
> type: 'number',
> aggregation: google.visualization.data.sum
> }]);
>
> On Wednesday, November 28, 2012 11:57:22 PM UTC-5, Heena wrote:
>>
>> Thanks Asgallant.This was really helpful.
>> Also is there any way to get the sum of an entire column. I tried using
>> google.visualization.data.sum
>> function but since it implements 'group by' function, so it did not work
>> out.
>>
>> On Thursday, November 29, 2012 3:33:13 AM UTC+5:30, asgallant wrote:
>>
>>> No, there's no way to set a property on a whole column. You can iterate
>>> over the data set easily, though:
>>>
>>> for (var i = 0; i < data.getNumberOfRows(); i++) {
>>> data.setProperty(i, column, 'className', 'myClass');
>>> }
>>>
>>> where data is your DataTable and column is the index of the column to
>>> adjust. If you have multiple columns that need adjusting, you can stick
>>> the indices in an array, and iterate over the array inside the row loop:
>>>
>>> for (var i = 0; i < data.getNumberOfRows(); i++) {
>>> for (var j = 0; j < columns.length; j++) {
>>> data.setProperty(i, columns[j], 'className', 'myClass');
>>> }
>>> }
>>>
>>> On Wednesday, November 28, 2012 2:43:14 PM UTC-5, Heena wrote:
>>>>
>>>> My data is dynamic , therefore I won't be sure about the number of rows
>>>> in my data table.
>>>> Also data is very large,so setting property for each and every column
>>>> won't be possible..
>>>> Doesn't the Api provide any possible way to format the allignment for
>>>> one complete column..?
>>>> Thanks in advanced..
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/4SZxZhN5nbMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.