javascript - 如何在 y 轴中仅设置最小值和最大值(图表 js)
解决方案
只有当前的主代码才有可能,在 chart.js 的下一个版本之后,使用普通的 CDN 就可以了
当前主分支代码示例:
var options = {
type: 'line',
data: {
labels: ["15/03/2020", "16/03/2020", "17/03/2020", "18/03/2020", "19/03/2020", "20/03/2020", "21/03/2020"],
datasets: [{
label: 'Dataset 1',
data: [10, 30, 50, 20, 25, 44, -10],
borderColor: 'red',
backgroundColor: 'red'
},
{
label: 'Dataset 2',
data: [10, 30, 50, 20, 25, 44, -10],
borderColor: 'blue',
backgroundColor: 'blue',
yAxisID: 'y2',
}
]
},
options: {
scales: {
y: {
type: 'linear',
position: 'left',
stack: 'demo',
ticks: {
min: -20,
max: 70
},
grid: {
borderColor: 'red'
},
title: {
display: true,
text: 'title1'
}
},
y2: {
type: 'linear',
offset: true,
position: 'left',
stack: 'demo',
ticks: {
min: -20,
max: 70
},
grid: {
borderColor: 'blue'
},
title: {
display: true,
text: 'title2'
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://www.chartjs.org/dist/master/chart.js"></script>
</body>
推荐阅读
- javascript - 如何将 JavaScript 对象与 html 表单一起发送?
- python - NEAT 错误 - AttributeError:“元组”对象没有属性“连接”
- c# - Selenium 查找选择节点的 xpath
- javascript - 从 json 初始化日历时加载了太多事件
- azure-data-factory - 当同一源上有多个复制数据活动时,Azure Purview 如何在 Azure 数据工厂中执行数据沿袭?
- ios - SwiftUI TabView PageTabViewStyle 防止更改标签?
- c - 与 C 中的 fseek() 混淆
- hadoop - 蜂巢安装
- c# - .NET Core 中的主键继承
- c - 消息队列未按预期接收信息