[英]Google Charts - avoid showing negative values on axis
即使包括 vAxis: {minValue:0} 也沒有用
如何避免在 yAxis 中顯示負值?
當不存在值時會發生這種情況。 在這種情況下,我不希望軸上出現負值
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>
我嘗試了幾種替代方案,但沒有一個成功。
嘗試使用ticks
選項...
vAxis: {
ticks: [0, 1, 2]
},
請參閱以下工作片段...
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.