Google条形图:重复绘制的行数

时间:2019-03-22 13:54:24

标签: charts google-visualization

我正在以Google条形图显示面部表情检测程序的结果。问题在于,对于返回的每个结果集,图表绘制的行数都是原来的两倍。

BarGraphWithDuplicates

<script>
document.getElementById("result").innerHTML;
google.charts.load('current', {packages: ['corechart', 'bar']});
</script>
	<button onclick="stopTextColor();">Stop</button>	
	<img id="bg" width=1200px height=900px src="{{ url_for('calc') }}">
	<div id="chart"></div>
	</body>
<script type="text/javascript">

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);
    }
    
</script>

当我检查返回的数组时,只有7个,但是如您所见,该图显示了14个。接下来的7行是前7个的副本。我不确定我要去哪里错误这里。有人可以帮我这个忙吗?

1 个答案:

答案 0 :(得分:0)

删除此声明...

tdata.addRows(data.result);

行已在此处添加...

var tdata = google.visualization.arrayToDataTable(data.result, true);