Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

put labels on top of inside bar in google interactive bar chart

I have created a bar chart using google Column Chart, now

  1. I have only integer values in my datatable but google divide acis with float values, is there a way to force chart mark only integers?
  2. is there any way to show value labels on top or inside bar chart? I found some way for image chart, but I whould like to keep chart interactive
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no direct solution to this as yet because annotations are not supported in column chart. But let me share a work around for this: You can create a combo chart with two series having same data (as that of your column chart) along with the annotation column. Set the type of the first series to bars and that of the other series to line. Finally, specify visibleInLegend, lineWidth, and pointSize properties of the second series to false and 0s respectively.

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...