DEV Community

Discussion on: Data visualization: Using amCharts with Perl and Mojo

Collapse
 
slobo profile image
Slobodan Mišković

Thanks for the article.

What is the reasoning of this line - does it cover some edge case?

var chartData = JSON.parse(JSON.stringify((<%== $chart_data %>)))
Enter fullscreen mode Exit fullscreen mode

From what I understand, $chart_data is already encoded as json, so you should be able to just do

var chartData = <%== $chart_data %>)
Enter fullscreen mode Exit fullscreen mode

Or skip the assignment altogether, and pass it in right away:

createMultiLineChart(<%== $chart_data %>);
Enter fullscreen mode Exit fullscreen mode

Cheers

Collapse
 
raigaurav profile image
Gaurav Rai

Thanks for the catch. The JSON parsing is absolutely not needed on JS side.
I remember I was doing some hit and trail before encoding it as JSON on server side and forgot it to remove later. Since everything is working fine, I didn't catch it. That is an extra performance overhead on JS side by cloning it.
I will remove it. Thank you.