0

I made a chart that included 30 days of absent data and I made it using the react-chartjs-2 library but the results are not responsive how to make it responsive?

this is what it looks like on a laptop: chart on laptop

and this if it looks on mobile: chart on mobile

this is my code:

  this.state = {
  loadFirst: true,
  loadData: false,
  filterYear: moment().format('YYYY'),
  filterMonth: moment().format('MM'),
  filtered: {
    year: moment().format('YYYY'),
    month: moment().format('MM')
  },
  data: {},
  options: {
    scales: {
      yAxes: [
        {
          stacked: true,
          ticks: {
            beginAtZero: true
          }
        }
      ],
      xAxes: [
        {
          stacked: true
        }
      ]
    }
  }
}

and this:

<Bar data={data} options={options} />}

how to fix it?

1 Answers1

0

There are limitations to how small you can go because chart.js still needs to draw it, you can disable the legend while on mobile to give the chart a bit more space to work with since its taking up most of the canvas or you can increase the size of the canvas

LeeLenalee
  • 27,463
  • 6
  • 45
  • 69