I'm showing the results of a face emotion detection program as a google bar chart. The problem is that for every result set that is returned, the chart draws double the number of rows.
BarGraphWithDuplicates
document.getElementById("result").innerHTML;
google.charts.load('current', {packages: ['corechart', 'bar']});
var intervalID = setInterval(update_values,1000);
function update_values() {
$.getJSON($SCRIPT_ROOT + '/result',
function(data) {
$('#result').text(data.result);
console.log(data);
drawMultSeries();
function drawMultSeries() {
var tdata = google.visualization.arrayToDataTable(data.result, true);
tdata.addRows(data.result);
var options = {
height: 500,
width: 500,
chartArea:{left:100,top:100,right:100,bottom:100},
hAxis: { ticks: [25,50,75,100] },
isStacked: false,
bar: {groupWidth: '10'},
vAxis:{ textStyle:{color: '#000000',fontSize: '12', paddingRight: '0',marginRight: '0'}},
colors: ['green','#ffff99','#ffbf0c','red'],
};
var chart1 = new google.visualization.BarChart(document.getElementById('chart'));
chart1.draw(tdata, options);
}
});
};
function stopTextColor() {
clearInterval(intervalID);
}
Run code snippetExpand snippet
When I inspect the array that is returned, there are only 7, but the graph as you can see shows 14. The next 7 rows are a replica of the first 7. I'm not sure where I'm going wrong here. Can someone please help me out with this?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)