Charts.js折线图,如果数据相同,如何隐藏y轴开始和结束标签

时间:2014-12-12 06:12:00

标签: javascript linechart chart.js

我是Charts.js的新手,如果数据返回所有相同的水平线,我一直在寻找隐藏/删除y轴开始和结束标签(下方和上方)的信息。有谁知道吗?

这是一个例子。

(y轴)

67878196

67878195 ---- o ---- o ---- o ---- o ---- o

67878194 =================(x轴)

我想隐藏/删除开始和结束标签,只显示67878195.感谢任何建议和提示。

此致

1 个答案:

答案 0 :(得分:1)

希望这有助于您: (它隐藏了y轴上的第一个和最后一个标签)

var myChart2 = new Chart(document.getElementById("canvas2"), {
  type: 'bar',
  data: data,
  options: {
   responsive: true,
title: {
  display: true,
  text: "Chart.js - Modified Chart Hiding Min/Max"
},
tooltips: {
  mode: 'index',
  intersect: false
},
legend: {
  display: false,
},
scales: {
  yAxes: [{
    afterTickToLabelConversion: function(scaleInstance) {
      // set the first and last tick to null so it does not display
      // note, ticks[0] is the last tick and ticks[length - 1] is the first
      scaleInstance.ticks[0] = null;
      scaleInstance.ticks[scaleInstance.ticks.length - 1] = null;

      // need to do the same thing for this similiar array which is used internally
      scaleInstance.ticksAsNumbers[0] = null;
      scaleInstance.ticksAsNumbers[scaleInstance.ticksAsNumbers.length - 1] = null;
    },
    ticks: {
      min: 10,
      max: 90,
    },
  }],
}
 }});

完整代码:https://codepen.io/jordanwillis/pen/jBeWWN