The secret to making jsfiddle work with the Viz API is to add 
"http://www.google.com/jsapi?.js"; as a resource.  jsfiddle needs an 
extension on the URL in order to discern javascript resources from css 
resources (given by "?.js" in the URL - this has no effect on loading the 
API, it just makes jsfiddle work).

On Monday, December 23, 2013 5:36:32 PM UTC-5, Sudhir Kesharwani wrote:
>
> Hi,
>
> After much struggle I was able to get to a solution. Here is how my code 
> looks like.
>
> /*This function generates array for aggrigate columns on pivot data*/
>> function getAggrColumns()
>> {
>>     var colArray = new Array();
>>     $.each(distinctProjects,function(index,value)
>>     {
>>         var colIndex = parseInt(index)+1;
>>         colArray.push({column: colIndex,type: 'number',label: 
>> view.getColumnLabel(parseInt(colIndex)),aggregation: 
>> google.visualization.data.sum});   
>>     });           
>>    return colArray;
>> }
>> /*Below function will generate the columns based on number of projects in 
>> the datatable*/
>> function getViewColumn()
>> {
>>     var colArray = new Array();
>>     colArray.push(3);
>>       
>>     $.each(distinctProjects,function(index,value){
>>      colArray.push({type: 'number',label: value,calc: function (dt, 
>> row){return (dt.getValue(row, 1) == value) ? dt.getValue(row, 2) : 
>> null;}});   
>>     });           
>>    return colArray;
>> }
>> //get an array of distinct projects (a,b,c,d) etc.
>> var distinctProjects = arrProjects.unique();
>> //create views based on dynamic number of columns
>> var view = new google.visualization.DataView(dataProject);
>> /*Get list of columns based on unique projects*/
>> myarr = getViewColumn();
>> //Set the above array as columns in the view.
>> view.setColumns(myarr);
>> /*Get the collection for aggrigate columns settings*/
>> var aggrCols = getAggrColumns();
>> //**Generate pivot data dynamically based on number of columns
>> var pivotedDataProjects = google.visualization.data.group(view, 
>> [0],aggrCols);
>
>
> Sorry for sharing this in bad format,  i couldnt configure JSFiddle to 
> work with Google Visualization API :) would try harder next time.
>
> On Wednesday, 11 December 2013 17:29:58 UTC-6, asgallant wrote:
>>
>> Updating this to allow pivoting an arbitrary number of row values into 
>> columns has been on my to-do list for a while.  I refactored the base code 
>> to enable this: http://jsfiddle.net/asgallant/HkjDe/
>>
>> On Wednesday, December 11, 2013 5:59:34 PM UTC-5, Sudhir Kesharwani wrote:
>>>
>>> Hello Champs,
>>>
>>> I am in a situation with Google Table / Charts. and would like to 
>>> convert it onto Pivot Table (http://jsfiddle.net/asgallant/HkjDe/ this 
>>> link contains the solution that worked like charm for me earlier *thanks 
>>> asg*)
>>>
>>> My Table has following structure,  I could have any number of projects 
>>> in future.
>>>
>>>   Year Project Resources  2013 A 25  2012 B 2  2014 A 5  2012 C 6  2015 
>>> A 56  2014 D 5  2013 A 6  2013 N 5  … … … 
>>> I would like to transform this table as a pivot table where each project 
>>> becomes a column of the table.
>>>
>>>    Year A B C D … N  2012 5 0 2 0 2 0  2013 0 55 0 5 6 6  2014 6 44 44 
>>> 55 0 0  2015 66 0 0 0 55 55 
>>> The issue here is that i am not aware of the number of columns so i will 
>>> have to generate columns based on index and script in an array.
>>>
>>> var myarr = [0, {
>>>         type: 'number',
>>>         label: VARIABLE,
>>>         calc: function (dt, row) { return (dt.getValue(row, 1) == 
>>> VARIABLE) ? dt.getValue(row, 2) : null;
>>>         }}]
>>>
>>> I was thinking of creating an array with script blocks. How would i be 
>>> able to store some number and script blocks into the same array. 
>>>
>>

-- 
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/groups/opt_out.

Reply via email to