繁体   English   中英

如何删除 Chart.js 条形图上的底部刻度

[英]How do remove the bottom scale on a Chart.js bar chart

我正在使用 Chart.js 创建以下图表:

在此处输入图像描述

问题是我想让底部的比例只显示 0 和最大数字(这里是 12)。

JavaScript:

<script> new Chart(document.getElementById("leads-bar"), { type: 'horizontalBar', data: { labels: ["Hot", "Warm", "Cold"], datasets: [ { backgroundColor: ["#d23232", "#ff9347", "#bbbbbb"], data: [7, 9, 11] } ] }, options: { legend: { display: false }, tooltips: { display: false }, title: { display: false }, scales: { xAxes: [{ stacked: true, gridLines: { display: false, drawBorder: false, }, scaleShowLabels: false, }], yAxes: [{ stacked: false, gridLines: { color: ["#eeeeee"] } }] } } });

 var dataArr = [154.23, 203.21, 429.01, 637.41]; var chart = new Chart(ctx, { type: 'horizontalBar', data: { labels: [154.23, 203.21, 429.01, 637.41], datasets: [{ label: 'LINE', data: dataArr, backgroundColor: 'rgba(0, 119, 290, 0.2)', borderColor: 'rgba(0, 119, 290, 0.6)', fill: false, tension: 0 }] }, options: { scales: { xAxes: [{ ticks: { min: Math.min.apply(this, dataArr), max: Math.max.apply(this, dataArr), callback: function(value, index, values) { if (index === values.length - 1) return Math.min.apply(this, dataArr); else if (index === 0) return Math.max.apply(this, dataArr); else return ''; } } }] } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script> <canvas id="ctx"></canvas>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM