javascript - Customizing tooltip on Google Timeline Chart -
i created google timeline chart see musical listening history. looks this:
i want remove duration part tooltip, couldn't find option it. tried adding these lines:
datatable.addcolumn({type: 'string', role:'tooltip'});
and row in datatable.addrows([])
function looks this:
['25 august', 'kasabian - la fee verte', new date(2016,01,01, 13,37,32), new date(2016,01,01, 13,43,19), 'tooltip example'],
but still shows same tooltip in image. want show kasabian - la fee verte , 25 august: 1:37 pm - 1:43 pm
in image, want remove duration.
according data format timeline chart, tooltip should in 3rd column.
see following, working snippet...
google.charts.load('current', { callback: function () { var container = document.getelementbyid('chart_div'); var chart = new google.visualization.timeline(container); var datatable = new google.visualization.datatable(); datatable.addcolumn({type: 'string', id: 'rowlabel'}); datatable.addcolumn({type: 'string', id: 'barlabel'}); datatable.addcolumn({type: 'date', id: 'start'}); datatable.addcolumn({type: 'date', id: 'end'}); datatable.addrows([ ['25 august', 'kasabian - la fee verte', new date(2016,01,01, 13,37,32), new date(2016,01,01, 13,43,19)], ['26 august', 'test data 1', new date(2016,01,01, 13,37,32), new date(2016,01,01, 13,43,19)], ['27 august', 'test data 2', new date(2016,01,01, 13,37,32), new date(2016,01,01, 13,43,19)], ]); datatable.insertcolumn(2, {type: 'string', role: 'tooltip', p: {html: true}}); var dateformat = new google.visualization.dateformat({ pattern: 'h:mm a' }); (var = 0; < datatable.getnumberofrows(); i++) { var tooltip = '<div class="ggl-tooltip"><span>' + datatable.getvalue(i, 1) + '</span></div><div class="ggl-tooltip"><span>' + datatable.getvalue(i, 0) + '</span>: ' + dateformat.formatvalue(datatable.getvalue(i, 3)) + ' - ' + dateformat.formatvalue(datatable.getvalue(i, 4)) + '</div>'; datatable.setvalue(i, 2, tooltip); } chart.draw(datatable, { tooltip: { ishtml: true } }); }, packages: ['timeline'] });
.ggl-tooltip { border: 1px solid #e0e0e0; font-family: arial, helvetica; padding: 6px 6px 6px 6px; } .ggl-tooltip span { font-weight: bold; }
<script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div>
Comments
Post a Comment