Equivalent for Select category , count as cnt group by category query

153 views
Skip to first unread message

Coltrane

unread,
Apr 23, 2012, 2:59:35 PM4/23/12
to Google Visualization API
Folks:
I attempting to use a SharePoint list as the source for bar graph and
in the the client side query language that I must use (caml) does not
support the count function. Does anyone know of another manner to
query the SP list as the graph datasource to gain category totals?

Thanks in advance.

Mark

asgallant

unread,
Apr 23, 2012, 3:09:01 PM4/23/12
to google-visua...@googlegroups.com
I can't speak to using Sharepoint as a data source, but you if I understand what you want correctly, you could use the Viz API's built in Group function to get totals.

asgallant

unread,
Apr 23, 2012, 3:17:04 PM4/23/12
to google-visua...@googlegroups.com
Example code might help.  This groups by column 0 in the DataTable and outputs a DataTable with distinct entries in column 0 and the count in column 1:

var counts google.visualization.data.Group(data[0][{
    column0,
    type'number',
    label'Count',
    aggregationgoogle.visualization.data.count
}]);

Coltrane

unread,
Dec 2, 2012, 12:36:17 PM12/2/12
to google-visua...@googlegroups.com
asgallant:
 
I've tried applying your code with no luck. I've reviewed the group documentation and here's what I'm doing:
creating datatable and populating it with my source data:
 
 var data = new google.visualization.DataTable();
 data.addColumn('string', 'Workflow Stage');
  data.addColumn('string', 'Project Name');
 
then I add the source data:
 
 data.addRows([[currentEmplyee.get_item("WFStage"),currentEmplyee.get_item("Project_x0020_Name")]]);
 
I add your code for the creation of the new datatable with an input of the data table I created with my source table:
 
var counts = google.visualization.data.Group(data, [0], [{column: 0, type: 'number', label: 'Count',aggregation: google.visualization.data.count}]);
 
get my html element:
 
 var table = new google.visualization.Table(document.getElementById('table_div'));
 
now draw my table:
 
  table.draw(counts, {allowHtml: true,showRowNumber: true});
 
my code executes correctly until it reaches the "var counts" line.
 
no table is drawn. What am I doing wrong??
 
Thanks in advance.
 
Mark

asgallant

unread,
Dec 3, 2012, 12:10:00 AM12/3/12
to google-visua...@googlegroups.com
Oops, "Group" shouldn't be capitalized there.  It should be 

var counts google.visualization.data.group(data[0][{

    column0,
    type'number',
    label'Count',
    aggregationgoogle.visualization.data.count
}]);

Coltrane

unread,
Dec 3, 2012, 9:15:11 AM12/3/12
to google-visua...@googlegroups.com
asgallant:
 
Thank You!!!! I changed "group" to lowercase and the code worked perfectly.
 
Mark.
Reply all
Reply to author
Forward
0 new messages