简体   繁体   English

谷歌图表 - 避免在轴上显示负值

[英]Google Charts - avoid showing negative values ​on axis

Even including vAxis: {minValue:0} didn't work即使包括 vAxis: {minValue:0} 也没有用

How can I do to avoid showing negative values in the yAxis?如何避免在 yAxis 中显示负值?

This happens when no value exists.当不存在值时会发生这种情况。 In this case I don't want negative values ​​to appear on the axis在这种情况下,我不希望轴上出现负值

 google.charts.load('current', {packages: ['corechart','bar'],'language': 'pt'}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var arrayToData = [['Date','','Data',{role: 'style'},{role:'tooltip', 'p': {'html': true}}]]; arrayToData.push(['01/06', 0,0,'','']); arrayToData.push(['02/06', 0,0,'','']); arrayToData.push(['03/06', 0,0,'','']); var data = new google.visualization.arrayToDataTable(arrayToData); var options = google.charts.Bar.convertOptions( { tooltip: {isHtml: true}, chartArea: { height: '100%', width: '100%', top: 38, left: 15, right: 100, bottom: 48 }, vAxis: { viewWindow:{ min: 0 } }, yAxis:{ viewWindowMode: "explicit", viewWindow:{ min: 0 } }, series: { 0: {enableInteractivity: false,targetAxisIndex: 0, visibleInLegend: false, pointSize: 0, lineWidth: 0,type: 'line',textStyle: {fontSize: 0}}, 1: { targetAxisIndex: 1, } }, vAxes: { 0: {textPosition: 'none'}, 1: {}, }, }); var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); }
 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div>

I've tried several alternatives and none have been successful.我尝试了几种替代方案,但没有一个成功。

try using the ticks option...尝试使用ticks选项...

                vAxis: {
                    ticks: [0, 1, 2]
                },

see following working snippet...请参阅以下工作片段...

 google.charts.load('current', {packages: ['corechart','bar'],'language': 'pt'}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var arrayToData = [['Date','','Data',{role: 'style'},{role:'tooltip', 'p': {'html': true}}]]; arrayToData.push(['01/06', 0,0,'','']); arrayToData.push(['02/06', 0,0,'','']); arrayToData.push(['03/06', 0,0,'','']); var data = new google.visualization.arrayToDataTable(arrayToData); var options = { tooltip: {isHtml: true}, chartArea: { height: '100%', width: '100%', top: 38, left: 15, right: 100, bottom: 48 }, vAxis: { ticks: [0, 1, 2] }, series: { 0: {enableInteractivity: false,targetAxisIndex: 0, visibleInLegend: false, pointSize: 0, lineWidth: 0,type: 'line',textStyle: {fontSize: 0}}, 1: { targetAxisIndex: 1, } }, vAxes: { 0: {textPosition: 'none'} }, }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); }
 <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM