Google visualization 在柱形图Google图表中显示数据值
我使用谷歌可视化创建了一个图表,但无法获取第二列的数据值Google visualization 在柱形图Google图表中显示数据值,google-visualization,Google Visualization,我使用谷歌可视化创建了一个图表,但无法获取第二列的数据值 var data = google.visualization.arrayToDataTable([ ['Year', 'Sales', 'Expenses'], ['2004', 1000, 400], ['2005', 1170, 460], ['2006', 660, 1120], ['2007', 1030, 540] ]); var view = ne
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1,{
calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation"
},
2]);
var options = {
title: 'Company Performance',
hAxis: { title: 'Users', titleTextStyle: { color: 'red', fontSize: 16} },
legend: { position: 'bottom', textStyle: { color: 'blue', fontSize: 16} }
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(view, options);
数据值用于销售但不用于费用列您需要在视图中添加另一个注释列:
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation"
}, 2, {
calc: "stringify",
sourceColumn: 2,
type: "string",
role: "annotation"
}]);
setColumns([{calc:function(data,row){return data.getFormattedValue(row,0);},type:'string'},1,2]) 你能把你的答案格式化成密码,并解释一下吗?最好避免只使用代码的答案,因为除了解决他们的特定问题外,它们不会帮助其他人。欢迎使用StackOverflow。请花点时间学习如何正确格式化代码。对代码的一些评论(为什么应该这样做)也很感激。