简体   繁体   English

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

[英]Charts.js line chart, how to hide y-axis start and end label if data is same

I am new to Charts.js and I have been looking for information how to hide/remove y-axis start and end labels (below and above) if data returned all same horizontal line. 我是Charts.js的新手,我一直在寻找信息,如果数据返回的所有水平线相同,则如何隐藏/删除y轴的开始和结束标签(上下)。 Does anyone know? 有人知道吗?

Here is an example. 这是一个例子。

(y-axis) (y轴)

67878196 67878196

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

67878194 ================= (x-axis) 67878194 =(= x = x ===========

I would like to hide/remove start and end labels and just display 67878195. Any advice and tips are appreciated. 我想隐藏/删除开始和结束标签,只显示67878195。我们欢迎您提出任何建议和提示。

Regards, 问候,

Hope this helps you: (It hides first and last labels in y axis) 希望这对您有帮助:(它在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,
    },
  }],
}
 }});

complete code on : https://codepen.io/jordanwillis/pen/jBeWWN 完整的代码在: https : //codepen.io/jordanwillis/pen/jBeWWN

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

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