Thanks Daniel,

I guessed it was still a string  The drawchart method works just as well as 
anything and accepts practically anything in  its option list so I really 
was just exploring possibilities.

I also tried eval() and that returns the strict JSON response as well.

Ray

On Tuesday, November 21, 2023 at 12:38:28 PM UTC-5 Daniel LaLiberte wrote:

> Hi Ray
>
> Your chartStr is still a string, not an expression, even though it looks 
> like an expression when you print it out.  At best, you would have to 
> evaluate the string to turn it into code.
>
> The drawChart function and ChartWrapper class do a lookup of the string 
> name of a chartType in order to interpret the string as a chart type that 
> can be executed.  Doing that may require dynamically loading more packages, 
> if they are not already loaded.
>
> On Mon, Nov 20, 2023 at 10:00 PM 'Ray Thomas' via Google Visualization API 
> <google-visua...@googlegroups.com> wrote:
>
>> 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#drawchart
>>
>> but am curious about the template strings.
>>
>> The working code can be see at https://brisray.com/utils/awslogs/
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Visualization API" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-visualizati...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/google-visualization-api/d421ba86-9892-4c83-a635-dce9f99a47e3n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/google-visualization-api/d421ba86-9892-4c83-a635-dce9f99a47e3n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
>
> • Daniel LaLiberte
>
>  • SWE
>
>  • Cambridge MA
>
>  • dlalibe...@google.com
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-visualization-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/ec1a3f70-d7c9-4096-943e-d0eb8df1d9bdn%40googlegroups.com.

Reply via email to