javascript - Google charts formatter not modifying tooltip -
i trying create line chart using google charts libraries.
the data contains, date (x axis), number (col 1), number (col 2), float (col 3).
i want display 2 decimals on 3rd column tooltip while keeping y axis 0 100, current code (running here https://jsfiddle.net/uqh56hsu/1/):
google.charts.load('current', {'packages':['line']}); google.charts.setonloadcallback(drawchart); function drawchart() { var data = new google.visualization.datatable(); data.addcolumn('datetime', 'hours'); data.addcolumn('number', 'col1'); data.addcolumn('number', 'col2'); data.addcolumn('number', 'percent'); data.addrows([ [new date(1454950800*1000),0,0,0],[new date(1454947200*1000),0,0,0],[new date(1454943600*1000),2,0,0.00],[new date(1454940000*1000),24,1,4.17],[new date(1454936400*1000),12,1,8.33],[new date(1454932800*1000),64,4,6.25],[new date(1454929200*1000),176,11,6.25],[new date(1454925600*1000),142,7,4.93],[new date(1454922000*1000),114,7,6.14],[new date(1454918400*1000),0,0,0],[new date(1454914800*1000),0,0,0],[new date(1454911200*1000),0,0,0],[new date(1454907600*1000),0,0,0],[new date(1454904000*1000),0,0,0],[new date(1454900400*1000),0,0,0],[new date(1454896800*1000),0,0,0],[new date(1454893200*1000),0,0,0],[new date(1454889600*1000),0,0,0],[new date(1454886000*1000),0,0,0],[new date(1454882400*1000),0,0,0],[new date(1454878800*1000),0,0,0],[new date(1454875200*1000),0,0,0],[new date(1454871600*1000),180,10,5.56], ]); var formatter = new google.visualization.numberformat({ fractiondigits: 2, suffix: '%' }); formatter.format(data, 3); var options = { width: 900, height: 500, backgroundcolor: '#f1f1f1', colors: ['#ff851b', '#03a9f4', '#8dc859'], dateformat: 'h', vaxes:[ { titletextstyle: {color: '#ff0000'}}, { titletextstyle: {color: '#ff0000'}, minvalue: 0, maxvalue: 100, format: '#\'%\'', viewwindowmode : 'explicit', viewwindow:{ max:100, min:0 }} ], series:[ {targetaxisindex:0}, {targetaxisindex:0}, {targetaxisindex:1} ] }; var chart = new google.charts.line(document.getelementbyid('linechart_material')); chart.draw(data, google.charts.line.convertoptions(options)); } i've tried adding formatter code earlier , later in code, trying apply other columns, etc, nothing seem work. 3rd column tooltip gets decimals removed.
what doing wrong?
the format being set in vaxes option, overriding formatter...
just set format --> format: '#,##0.00\'%\''
no need formatter here...
google.charts.load('current', {'packages':['line']}); google.charts.setonloadcallback(drawchart); function drawchart() { var data = new google.visualization.datatable(); data.addcolumn('datetime', 'hours'); data.addcolumn('number', 'col1'); data.addcolumn('number', 'col2'); data.addcolumn('number', 'percent'); data.addrows([ [new date(1454950800*1000),0,0,0], [new date(1454947200*1000),0,0,0], [new date(1454943600*1000),2,0,0.00], [new date(1454940000*1000),24,1,4.17], [new date(1454936400*1000),12,1,8.33], [new date(1454932800*1000),64,4,6.25], [new date(1454929200*1000),176,11,6.25], [new date(1454925600*1000),142,7,4.93], [new date(1454922000*1000),114,7,6.14], [new date(1454918400*1000),0,0,0], [new date(1454914800*1000),0,0,0], [new date(1454911200*1000),0,0,0], [new date(1454907600*1000),0,0,0], [new date(1454904000*1000),0,0,0], [new date(1454900400*1000),0,0,0], [new date(1454896800*1000),0,0,0], [new date(1454893200*1000),0,0,0], [new date(1454889600*1000),0,0,0], [new date(1454886000*1000),0,0,0], [new date(1454882400*1000),0,0,0], [new date(1454878800*1000),0,0,0], [new date(1454875200*1000),0,0,0], [new date(1454871600*1000),180,10,5.56] ]); var options = { width: 900, height: 500, backgroundcolor: '#f1f1f1', colors: ['#ff851b', '#03a9f4', '#8dc859'], dateformat: 'h', vaxes:[ { titletextstyle: {color: '#ff0000'} }, { titletextstyle: { color: '#ff0000' }, minvalue: 0, maxvalue: 100, format: '#,##0.00\'%\'', // set format here -- formatter not needed viewwindowmode : 'explicit', viewwindow: { max:100, min:0 } } ], series:[ {targetaxisindex:0}, {targetaxisindex:0}, {targetaxisindex:1} ] }; var chart = new google.charts.line(document.getelementbyid('linechart_material')); chart.draw(data, google.charts.line.convertoptions(options)); } <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="linechart_material"></div>
Comments
Post a Comment