chart.js - 对数 yaxsis 设置在 chartjs 中不起作用
问题描述
我以前在 plotly 方面有过经验,现在我正在尝试使用 Chart.js 进行类似的图表。在 plotly 我可以设置yaxis_type="log"
,它将自动缩放 Y 轴的值。我正在尝试在 chart.js 中做类似的事情,但无法实现所需的输出。
Y 轴从 0 开始,直接跳到 20000 ,因此很难将前三行可视化。我希望它根据值进行相应的缩放。
我的 JS 代码:
<script type="text/javascript">
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: {{xaxis|safe}},
datasets: {{data_Categoryline|safe}}
},
options: {
title: {
display: true,
text: 'Category wise Trend'
},
scales: {
xAxes: [{
display : true,
scaleLabel :{
display : true,
labelString : 'Across the days/weeks/months'
}
}],
yAxes: [{
ticks: {
beginAtZero: false,
type: 'logarithmic'
},
scaleLabel :{
display : true,
labelString : 'Total Amount'
}
}]
},
legend: {
position : 'right'
}
}
});
</script>
解决方案
轴type
不能在ticks
选项内部定义,而是直接在轴上定义,如下所示:
yAxes: [{
type: 'logarithmic',
ticks: {
beginAtZero: false
},
请参阅Chart.js 文档中的笛卡尔坐标轴通用配置。
推荐阅读
- javascript - 使用 javascript(Tampermonkey 脚本)在 React 输入中输入文本?
- r - 如何在 R 中导入 .rec 文件
- scala - 如何最有效地在scala中合并和聚合2个地图?
- python - 按类 INSTAGRAM、selenium python 复制标题
- ruby-on-rails - 短信网关的 Fedena 短信设置
- sql-server - SELECT 语句返回 DATETIME 之外的行
- python - 无法在 Python 中使用 h2o 导入文件
- awk - 如何关联数据以使用 awk 执行命令操作?
- github - GitHub 如何猜测文件的编码?
- c# - 如何打印每行打印在新页面中的datagridview?