react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

each labels contains only 1 bar of data

Open jacky-ew opened this issue 5 years ago • 2 comments

may i know how to generate a bar chart with each labels contains its own bar of data

eg :

data = {
    labels: ["apple", "orange", "pear"],
    datasets: **this is the part where i stucked**
}

i want to have 3 bars displaying : apples -> a bar (10 apples), orange -> a bar (6 oranges), pear -> a bar (4 pears)

jacky-ew avatar Feb 27 '20 02:02 jacky-ew

@jacky-ew if you want to show labels without hover, you can use this lib https://www.npmjs.com/package/chartjs-plugin-datalabels

nicholasess avatar Apr 18 '20 13:04 nicholasess

Hi @jacky-ew 👋

If I understand your problem correctly, you can just set up datasets like so:

datasets: [
    {
      label: 'Fruit data',
      data: [10, 6, 4],
      backgroundColor: 'rgba(255, 99, 132, 0.5)',
      ...
    },
  ],

to achieve desired result.

Arantiryo avatar May 13 '22 18:05 Arantiryo