Ars*_*yan 2 google-visualization
我现在使用谷歌柱形图创建了一个条形图
小智 12
目前尚无直接解决方案,因为柱形图不支持注释.但是,让我分享一个解决方法:您可以创建一个组合图表,其中两个系列具有相同的数据(与柱形图的数据)以及注释列.将第一个系列的类型设置为条形,将另一个系列的类型设置为直线.最后,将第二个系列的visibleInLegend,lineWidth和pointSize属性分别指定为false和0.
var data = new google.visualization.DataTable();
data.addColumn({ type: 'string', label: 'Labels' });
data.addColumn({ type: 'number', label: 'Bar Series' });
data.addColumn({ type: 'number', label: 'Line Series' });
data.addColumn({ type: 'string', role: 'annotation' });
data.addRows([['Label1', 10, 10, '10'],
['Label1', 20, 20, '20'],
['Label1', 40, 40, '40'],
['Label1', 5, 5, '5'],
['Label1', 30, 30, '30'],
]);
var barchart = new google.visualization.ComboChart(document.getElementById('bar_element'));
var options = {series: [{ type: 'bars' },
{ type: 'line', lineWidth: 0, visibleInLegend:false, pointSize: 0}]};
barchart.draw(data, options);
Run Code Online (Sandbox Code Playgroud)