1
我有2个Google条形图,一个堆积,一个没有。我需要为两个图表中的每个细分添加注释。我怎样才能做到这一点?如何向分段的Google图表添加注释?
google.load('visualization', '1', {
'packages': ['corechart', 'table']
});
google.setOnLoadCallback(drawCharts);
function drawCharts() {
drawSixMonthHistory();
drawTagBreakdown();
};
function drawSixMonthHistory() {
var data = google.visualization.arrayToDataTable([
["Calendars", "Calendar A", "Calendar B", "Calendar C"],
["Dec, 2015", 0, 0, 0],
["Jan, 2016", 0, 0, 0],
["Feb, 2016", 0, 0, 0],
["Mar, 2016", 0, 0, 0],
["Apr, 2016", 3, 0, 2],
["May, 2016", 6, 2, 1]
]);
var view = new google.visualization.DataView(data);
var chart = new google.visualization.ColumnChart(document.getElementById('sixMonthHistory'));
chart.draw(view, {
fontName: 'Roboto',
enableInteractivity: false,
backgroundColor: 'transparent',
annotations: {
alwaysOutside: true
},
chartArea: {
width: '90%'
},
vAxis: {
viewWindowMode: 'explicit',
format: '##0',
viewWindow: {
min: 0
}
},
legend: {
position: 'bottom',
maxLines: 3
},
isStacked: true
});
}
function drawTagBreakdown() {
var data = google.visualization.arrayToDataTable([
["tags", "Tag A", "Tag B", "Tag C"],
["Dec, 2015", 0, 0, 0],
["Jan, 2016", 0, 0, 0],
["Feb, 2016", 0, 0, 0],
["Mar, 2016", 0, 0, 0],
["Apr, 2016", 3, 1, 3],
["May, 2016", 2, 1, 5]
]);
var view = new google.visualization.DataView(data);
var chart = new google.visualization.ColumnChart(document.getElementById('sixMonthTagHistory'));
chart.draw(view, {
fontName: 'Roboto',
enableInteractivity: false,
backgroundColor: 'transparent',
annotations: {
alwaysOutside: true
},
chartArea: {
width: '90%'
},
vAxis: {
viewWindowMode: 'explicit',
format: '##0',
viewWindow: {
min: 0
}
},
legend: {
position: 'bottom',
maxLines: 3
}
});
}
希望这会有所帮助,您可能需要使用自定义函数与'stringify'排除注解金额为零的 - 也许调整'注释:{alwaysOutside:true}' – WhiteHat