0

I am willing to draw Google Chart with a variable in the constructor.

Example:

    var chartType = 'BarChart';
    var chartTypeToDraw = new google.visualization.chartType(document.getElementById('chart'));

Is there a way to draw it based on defined chartType variable?

  • yes, see the answer here --> [Dynamic Change - Google Chart Type](https://stackoverflow.com/questions/40161527/dynamic-change-google-chart-type)... – WhiteHat Jun 14 '17 at 11:29

1 Answers1

0

to access a property by name, use brackets instead of .name...

var chartType = 'BarChart';
var chartTypeToDraw = new google.visualization[chartType](document.getElementById('chart'));
WhiteHat
  • 59,912
  • 7
  • 51
  • 133
  • using the [`ChartWrapper` class](https://stackoverflow.com/a/44440856/5090771) is another option... – WhiteHat Jun 14 '17 at 11:33