gpt4 book ai didi

javascript - 结合不同粒度的chart.js条形图和折线图

转载 作者:行者123 更新时间:2023-12-03 06:26:16 24 4
gpt4 key购买 nike

以下 HTML 页面生成组合的条形图和折线图:

<html>

<head>
<title>Combo Bar-Line Chart</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.bundle.js"></script>
<style>
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>

<body>
<div style="width: 800px">
<canvas id="canvas"></canvas>
</div>
<script>

var barChartData = {
labels: ["a","b","c","d","e","f","g"],
datasets: [{
type: 'bar',
label: 'Revenue Per Share',
backgroundColor: "#eeeeee",
data: [
4.24,
4.57,
4.70,
5.10,
5.25,
5.76,
6.19
],
borderColor: '#aaaaaa',
borderWidth: 1,
pointRadius: 0,
fill: true,
yAxisID: 'y-axis-1'
}, {
type: 'line',
label: 'Share Price',
backgroundColor: '#88CCFF',
data:
[
40,
90,
45,
50,
60,
70,
80
],
options: {
scales: {
xAxes: [{
ticks: {
max: 10,
min: 0,
stepSize: 0.5
}
}]
}
},
borderColor: '#aaaaaa',
borderWidth: 1,
pointRadius: 0,
fill: true,
yAxisID: 'y-axis-2'
}, ]
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
legend: {
display: false,
},
responsive: true,
tooltips: {
mode: 'label'
},
elements: {
line: {
fill: false
}
},
scales: {
xAxes: [{
display: true,
gridLines: {
display: false
},
labels: {
show: true,
}
}],
yAxes: [{
type: "linear",
display: true,
position: "left",
id: "y-axis-1",
gridLines:{
display: true
},
labels: {
show: true,

}
}, {
type: "linear",
display: true,
position: "right",
id: "y-axis-2",
gridLines:{
display: false
},
labels: {
show: true,

}
}]
}
}
});
};
</script>
</body>

</html>

这两种图表类型的每个数据集中的项目数目前相等。

我想增加折线图的粒度,以便它能够在同一区域内显示更多详细信息,但是,当将更多项目添加到折线图数据集中时,而不是显示更多详细信息,多余的项目将被删除关闭,因此不会显示它们。

            data: 
[
40,
60,
90,
60,
45,
55,
50,
55,
60,
65,
70,
75,
80
],

如何增加折线图的粒度?

最佳答案

labels 数组中的值的数量是将在图表上显示的值的数量。

关于javascript - 结合不同粒度的chart.js条形图和折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38640607/

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