gpt4 book ai didi

javascript - Chart.js 条形图改变标签位置X轴

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:03 25 4
gpt4 key购买 nike

我是 chart.js 的新手。我想绘制一个 x 轴标签不居中的条形图,但在两个条形连接的地方。这就是我需要创建的

https://i.imgsafe.org/12dcb3ea20.png

但在我当前的实现中(在下图中)标签以栏为中心。我需要标签位于两个条形连接的中间位置,如上图所示。

https://i.imgsafe.org/12e75a5888.jpg

这是我的代码

    window.onload = function() { 
init();
};

function init() {
var ctx = $("#myChart").get(0).getContext("2d");

var data = {
labels: ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"],
datasets: [
{
label: "My First dataset",
fillColor : "rgba(0, 173, 165, 1)",
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
borderWidth: 1,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
data: [5, 22, 30, 22, 26, 40, 60, 68, 40, 10],
}
]
};

var myNewChart = new Chart(ctx).Bar(data);
}

</script>
<div>
<section>
<article>
<canvas id="myChart" width="800" height="200">
</canvas>
</article>
</section>
</div>

最佳答案

尝试添加这些选项:

options : {
scales : {
xAxes : [{
gridLines: {
offsetGridLines : true
}
}]
}
}

关于javascript - Chart.js 条形图改变标签位置X轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37608068/

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