gpt4 book ai didi

javascript - Google 折线图 - 当没有数据传递时,vAxis 线显示在中间

转载 作者:行者123 更新时间:2023-11-28 04:30:47 26 4
gpt4 key购买 nike

这是我的代码

var data = new google.visualization.DataTable(
{
cols: [{ label: 'week', type: 'number' },
{ label: 'Completion', type: 'number' },
{ type: 'string', role: 'tooltip' }],
rows: progressList
}
);

var options = {
width: 400,
height: 265,
hAxis: {
title: 'Week',
titleTextStyle: { fontSize: 12 },
'margin-top': '20'
},
chartArea: { 'width': '82%', 'height': '75%' },
pointSize: 5,
legend: 'none',
tooltip: { showColorCode: true },
vAxis: {
title: 'Completion %',
titleTextStyle: { fontSize: 12 },
ticks: [0, 20, 40, 60, 80, 100]
}
};

chart.draw(data, options);

这就是当空数组 [] 传入图表时我的图表的外观。

enter image description here

有办法将 Vaxis 线向左移动吗?

最佳答案

设置选项 --> hAxis.viewWindow.min

hAxis: {
viewWindow: {
min: 0
}
},

请参阅以下工作片段...

google.charts.load('current', {
callback: drawChart,
packages:['corechart']
});

function drawChart() {
var data = new google.visualization.DataTable({
cols: [
{label: 'week', type: 'number'},
{label: 'Completion', type: 'number'},
{type: 'string', role: 'tooltip'}
],
rows: [
]
});

var options = {
width: 400,
height: 265,
hAxis: {
title: 'Week',
titleTextStyle: {
fontSize: 12
},
viewWindow: {
min: 0
}
},
chartArea: {
width: '82%',
height: '75%'
},
pointSize: 5,
legend: 'none',
tooltip: {
showColorCode: true
},
vAxis: {
title: 'Completion %',
titleTextStyle: {
fontSize: 12
},
ticks: [0, 20, 40, 60, 80, 100]
}
};

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

关于javascript - Google 折线图 - 当没有数据传递时,vAxis 线显示在中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44623318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com