How to hide y axis line in ChartJs?

2020-06-30 04:23发布

I am using bubble chart and gotta hide the y axis line. I've tried the following but it doesn't work.

yAxes: [{
  angleLines: {
    display: false
  }
}]

5条回答
该账号已被封号
2楼-- · 2020-06-30 04:44
var ctx = document.getElementById("myChart");

var data = {
    datasets: [
        {
            label: 'First Dataset',
            data: [
                { x: 20, y: 30, r: 10 },
                { x: 40, y: 10, r: 10 },
                { x: 30, y: 20, r: 30 }
            ]
        }]
};

var myBubbleChart = new Chart(ctx,{
    type: 'bubble',
    data: data,
    options: {
        scales:
        {
            yAxes: [{
                display: false
            }]
        }
    }
});
查看更多
做个烂人
3楼-- · 2020-06-30 04:50
var myBubbleChart = new Chart(ctx,{
    type: 'bubble',
    data: data,
    options: {
        scales:
        {
            yAxes: [{
                gridLines : {
                    display : false
                }
            }]
        }
    }
});
查看更多
女痞
4楼-- · 2020-06-30 05:03

This disables the vertical Y axis line:

options: {
  scales: {
    yAxes: [{
      gridLines: {
        drawBorder: false,
      },
    }]
  },
},

This can be combined with display to disable the vertical gridLines:

xAxes: [{
  gridLines: {
    display: false,
  },
}],

Here's a working example: http://codepen.io/anon/pen/xqGGaV

查看更多
在下西门庆
5楼-- · 2020-06-30 05:06

For the latest chart.js (v2.9.3) library: You can do this in chart options to disable a particular axis:

Disable A particular axis in the chart

This chart can be obtained like so:

  scales: {
      xAxes: [
        {
          gridLines: {
            display: false,
          },
        },
      ],
    },
查看更多
来,给爷笑一个
6楼-- · 2020-06-30 05:08

so if you only want to hide the grid lines only on the chart , but keep the axis line:

gridLines : {
    drawOnChartArea: false
}

With above examples it will be like:

var myBubbleChart = new Chart(ctx,{
    type: 'bubble',
    data: data,
    options: {
        scales:
        {
            yAxes: [{
                gridLines : {
                    drawOnChartArea: false
                }
            }]
        }
    }
});
查看更多
登录 后发表回答