Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

legend converting rectangle box to square - boxWidth not working

Open at-webdev opened this issue 5 years ago • 2 comments

With react-chartjs-2, creating Bar Graph as below. I am trying to make the legends in square shape rather than default rectangle.

I applied boxWidth: 10 as below but it doesn't work, Is there any other possible alternatives to generate a square legend

const sample_data = {
  labels: ['Item1', 'Item2'],
  datasets: [
    {
      data: [10, 10, 50],
      borderWidth: 1,
      backgroundColor: 'yellow',
    },
    { data: [20, 20, 20], 
      borderWidth: 1,
      backgroundColor: 'green' 
    },
  ],
};
const sample_options = {
  responsive: true,
  legend: {
    boxWidth: 10, // Also 0 doesn't make any change
  },
...
};
<Bar data={sample_data} options={sample_options} />;

Source: https://www.chartjs.org/docs/latest/configuration/legend.html#legend-label-configuration boxWidth - Width of coloured box.

at-webdev avatar Feb 11 '21 16:02 at-webdev

as stated in the documentation it falls under the labels key in the legend object

example: https://jsfiddle.net/Leelenaleee/yoh5su6t/

LeeLenaleee avatar Feb 11 '21 18:02 LeeLenaleee

as stated in the documentation it falls under the labels key in the legend object

example: https://jsfiddle.net/Leelenaleee/yoh5su6t/

Thanks @LeeLenaleee for noticing the gap.

at-webdev avatar Feb 11 '21 21:02 at-webdev