Google Charts -避免在轴上显示负值



即使包括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>

相关内容

  • 没有找到相关文章

最新更新