I thought I'd try using JavaScript's template strings to produce some charts, but cannot make them work. The idea was to pass a variable into the visualization chart code. The code I used was:
function newCharts(){
chartType=`BarChart`;
var chartStr = `google.visualization.${chartType}(document.getElementById('awstats-graph'))`;
console.log(chartStr);
newChart = new chartStr;
newChart.draw(drawData);
}
The console output looks OK and gives:
google.visualization.BarChart(document.getElementById('awstats-graph'))
But then I get the error:
Uncaught Error: Error handling Query strict JSON response: TypeError: chartStr is not a constructor
Does this mean there's something wrong with the code or that I cannot use this method?
I got what I wanted to do by using the drawchart method -
https://developers.google.com/chart/interactive/docs/reference#drawchartbut am curious about the template strings.
The working code can be see at
https://brisray.com/utils/awslogs/