https://i.imgur.com/qKcSRjS.png
从上到下的条形值为66,77,91,0
正如您所看到的,X轴上的标签不是按比例绘制的,似乎只是表示每个条形的值,并且条形图也没有缩放到它们的值,它们似乎只是以阶梯方式堆叠。底栏应为'空',因为它为0。
数据是动态生成的,但这里是生成的代码:
function drawRightY() {
var data = google.visualization.arrayToDataTable([ ['Date', 'Received'], ['1/15/2018', '66'],['1/22/2018', '77'],['1/29/2018', '91'],['2/5/2018', '0'] ]);
var materialOptions = {
chart: {
hAxis: {
title: 'Date',
minValue: 0,
scaleType: 'log'
},
vAxis: {
title: 'Received'
},
bars: 'horizontal',
legend: {
position: 'none'
},
axes: {
y: {
0: { side: 'left' }
}
}
};
答案 0 :(得分:1)
数据中的值应该是数字,而不是字符串(删除单引号)
['1/15/2018', '66'] // <-- string
['1/15/2018', 66] // <-- number
请参阅以下工作代码段...
google.charts.load('current', {
packages:['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([ ['Date', 'Received'], ['1/15/2018', 66],['1/22/2018', 77],['1/29/2018', 91],['2/5/2018', 0] ]);
var materialOptions = {
hAxis: {
title: 'Date',
minValue: 0,
scaleType: 'log'
},
vAxis: {
title: 'Received'
},
bars: 'horizontal',
legend: {
position: 'none'
},
axes: {
y: {
0: { side: 'left' }
}
}
};
var chart = new google.visualization.BarChart(document.getElementById('chart'));
chart.draw(data);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart"></div>