[英]Google charts annotation not showing
I am using the google charts api to display data from php.我正在使用 google charts api 来显示来自 php 的数据。 I am displaying this information in a material style bar chart (vertical).
我在材料样式条形图(垂直)中显示此信息。
I am trying to add annotations to show the values inside the bars however it isn't working.我正在尝试添加注释以显示条形图中的值,但它不起作用。
JavaScript: JavaScript:
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawLastPackets);
function drawLastPackets() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Days');
data.addColumn('number', 'Packets Packed');
data.addColumn({type: 'string', role: 'annotation'});
data.addRows(<?php echo json_encode($chartLastPackets); ?>);
var toAdd = ["Day", "Packets Packed", {"role": "annotation"}];
var options = {
legend: {
position: 'none',
},
series: {
0: {color: '#d7a8a8'}
},
vAxis: {
title: 'Packets'
}
};
var chart = new google.charts.Bar(document.getElementById('lastPackets'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
The contents of the php array $chartLastPackets
is: php 数组
$chartLastPackets
的内容是:
[["Mon", 1, "1"], ["Tue", 3, "3"], ["Wed", 5, "5"], ["Thu", 2, "2"], ["Fri", 0, "0"]]
However all I can see is the chart itself without the annotation.但是,我只能看到没有注释的图表本身。
annotations.*
are listed among the several options that don't work on Material charts annotations.*
列在对Material图表不起作用的几个选项中
you can use the following option, to get the chart close to the look & feel of Material您可以使用以下选项,使图表接近Material的外观和感觉
theme: 'material'
see following working snippet...请参阅以下工作片段...
google.charts.load('current', { callback: function () { var data = new google.visualization.DataTable(); data.addColumn('string', 'Days'); data.addColumn('number', 'Packets Packed'); data.addColumn({type: 'string', role: 'annotation'}); data.addRows([["Mon", 1, "1"], ["Tue", 3, "3"], ["Wed", 5, "5"], ["Thu", 2, "2"], ["Fri", 0, "0"]]); var options = { legend: { position: 'none', }, series: { 0: {color: '#d7a8a8'} }, theme: 'material', vAxis: { title: 'Packets' } }; var chart = new google.visualization.ColumnChart(document.getElementById('lastPackets')); chart.draw(data, options); }, packages: ['corechart'] });
<script src="https://www.gstatic.com/charts/loader.js"></script> <div id="lastPackets"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.