Same label in the pie chart - old code

14 views
Skip to first unread message

Kesava Peteti

unread,
May 26, 2016, 12:38:59 PM5/26/16
to Google Visualization API
Hi,

I have created a dashboard watching this Google developers video. After creating it I came to know that it's deprecated. However the dashboard is rendering but I need a little help.

There are multiple rows with same label with different data. When the chart renders, I'm seeing same labels more than once with the corresponding data. But what I want is one label and the sum of the data for that label.

I have attached the screenshot. Here is the code:

function doGet() {
  var ss = SpreadsheetApp.openById('1UzJ20BcH3DaFMeW-gr4wazidqhOtEWCMGEgYTu7-0CI');
  var data = ss.getDataRange();
  
  var countryFilter = Charts.newCategoryFilter()
       .setAllowMultiple(true)
       .setFilterColumnIndex(7)
       .setSortValues(true)
       .setLabelStacking(Charts.Orientation.VERTICAL)
       .setCaption('Choose County')
       .build();
  
  var pieChart = Charts.newPieChart()
       .setDataViewDefinition(Charts.newDataViewDefinition().setColumns([7,8]))
       .setDimensions(600, 500)
       .set3D()
       .build();
  
  var tableChart = Charts.newTableChart()
       .setDataViewDefinition(Charts.newDataViewDefinition().setColumns([7,8]))
       .build();
  
  var dashboard = Charts.newDashboardPanel()
       .setDataTable(data)
       .bind([ countryFilter], [pieChart, tableChart,])
       .build();
  
  var app = UiApp.createApplication();
  var filterPanel = app.createVerticalPanel();
  var chartPanel = app.createHorizontalPanel();
  filterPanel.add(countryFilter).setSpacing(10);
  chartPanel.add(pieChart).add(tableChart).setSpacing(10);
  
  dashboard.add(app.createVerticalPanel().add(filterPanel).add(chartPanel));
  app.add(dashboard);
  return app;
}

Tried searching old posts but couldn't find what I want. Any help would be much appreciated.

Thanks,
Kesava
screenshot.jpg
Reply all
Reply to author
Forward
0 new messages