Search code examples
chartsgoogle-visualizationorgchart

Can't get google orgchart selection in Angular2


My code looks like:

drawGraph() {
  let theChart;
  let handler = () => {
    let sel = theChart.getChart().getSelection();
    alert('selection occurred');
    console.log('selection event', sel, Object.keys(sel));
  };

  this.google = this.getGoogle();
  this.dataTable = this.getDataTable();
  this.orgData.fillDataTable(this.dataTable, 'PALA,SRINIVASRAO');
  console.log('data', this.dataTable);
  this.dataTable.setRowProperty(1, 'style', 'border: 0');
  this.chart = this.createWrapped('OrgChart', 'chartDiv', this.dataTable);
  theChart = this.chart;
  this.chart.draw();
  this.google.visualization.events.addListener(this.chart, 'select', handler);
}

The chart draws fine, My evert handler gets hit but the getSelection() only returns ["0"]. By the way the createWrapped is using google.visualization.ChartWrapper.

So what am I doing wrong? Besides trying to get this to work under TypeScript I mean. :)


Solution

  • getSelection() is a Chart method, not a ChartWrapper method

    instead...

    this.chart.getChart().getSelection()