I am coding a website getting data from an home made API and publishing that on a google chart.
on my chart area, I get a text or a red background “g is undefined”.
It is driving me crazy, any clue of what I am doing wrong?
google.charts.setOnLoadCallback(drawChart);
var chart
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Positive');
data.addColumn('number', 'Negative');
data.addColumn('number', 'Mixed');
data.addColumn('number', 'Neutral');
var request = new XMLHttpRequest()
// Open a new connection, using the GET request on the URL endpoint
request.open("POST", apiEndPoint + "/dailystats", true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify({"media":media,"period":parseInt(period)}));
request.onload = function() {
var restcall = JSON.parse(this.response)
if (request.status >= 200 && request.status < 400) {
restcall.forEach(metric => {
data.addRows([[metric.date,metric.sentiments.positive,metric.sentiments.mixed,metric.sentiments.neutral,metric.sentiments.negative]])
})
}
}
var options = {
chart: {
title: 'Box Office Earnings in First Two Weeks of Opening',
subtitle: 'in millions of dollars (USD)'
},
width: 900,
height: 500
};
chart = new google.charts.Line(document.getElementById('linechart_frame'));
chart.draw(data, google.charts.Line.convertOptions(options));
}```
Thanks!