Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display axis borders only (no grid lines) in chartjs?

Tags:

chart.js

So I only want to show the axes border lines - and hide the grid lines. This is using the latest version of the chart.js package (2.9.3) and I have replicated my issue in a simplified Codepen shown below:

var myChart = new Chart(ctx, {
type: 'scatter',
data: {
  labels: [4, 0],
  datasets: [{
    data: [
      { group_name: "Group A", x: 4, y: 25 },
      { group_name: "Group B", x: 0, y: 0 },
    ],
  }],
},
options: {
      legend: { display: false },
      scales: {
        yAxes: [ {
          type: 'logarithmic',
          scaleLabel: { display: true, labelString: 'Active %', fontSize: 15 },
          position: 'left',
          gridLines: { display: false, drawBorder: true },
          ticks: {
            min: 0,
            max: 50,
            maxTicksLimit: 4,
            padding: 10,
            callback: value => `${value.toLocaleString()}%`,
          },
        } ],
        xAxes: [ {
          type: 'logarithmic',
          position: 'bottom',
          scaleLabel: { display: true, labelString: 'User Count', fontSize: 15 },
          gridLines: { display: false, drawBorder: true },
          ticks: {
            min: 0,
            maxTicksLimit: 6,
            padding: 10,
            callback: value => value.toLocaleString(),
          },
        } ],
      },
    }
});

Any help or insight is appreciated; the settings I'd expect to work from the docs don't seem to be working.

like image 706
Eric Furspan Avatar asked Nov 14 '19 20:11

Eric Furspan


People also ask

How do I remove grid lines from a graph?

Click anywhere on the chart in which you want to hide chart gridlines. On the Layout tab, in the Axes group, click Gridlines. Do one or more of the following: Click Primary Horizontal Gridlines, Primary Vertical Gridlines, or Depth Gridlines (on a 3-D chart), and then click None.

How do you change axis color in Chartjs?

With ChartJS 3, you can change the color of the labels by setting the scales. x. ticks.

How do I make a Chartjs chart responsive?

The chart can also be programmatically resized by modifying the container size: chart.canvas.parentNode.style.height = '128px'; chart.canvas.parentNode.style.width = '128px'; Copied! Note that in order for the above code to correctly resize the chart height, the maintainAspectRatio option must also be set to false .


1 Answers

gridLines: { drawBorder: true, lineWidth: 0 }
like image 185
Dawid Mazewski Avatar answered Oct 18 '22 10:10

Dawid Mazewski