Chartjs-Removing labels from chart.js with a media query (or change option value)

1👍

Media query would be a good idea if it’s working, but I don’t know that.

I have a solution with chart.js but I don’t know if that’s what you want. Right now I remove the ticks completely (including grid lines) if the chart area is small enough. If you just want to hide the ticks you need to adapt the code a little bit like I do in the lines which I commented.

Complete code: https://jsbin.com/lifubiriye/edit?js,output

Important part:

function setChartWidth() {
  chartWidth = document.getElementById("chart").width

  if (chartWidth < 756) {
    myChart.options.scales.xAxes[0].display = false
  } else {
    myChart.options.scales.xAxes[0].display = true    
  }  
}

Leave a comment