Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create stacked bar chart using react-chartjs-2?

I have to create stacked bar chart using react-chartjs-2.

options : {
    maintainAspectRatio: false,
    tooltips: {
      mode: 'x-axis'
    },
    scales: {
      yAxes: [{
        ticks: {
          beginAtZero: true
        }
      }],
      xAxes: [{
        stacked: true
      }]
    }
  }

The stacked in Bar doesn't seem to work.

I am using [email protected]

like image 857
Rahul Kumar Avatar asked May 26 '17 09:05

Rahul Kumar


1 Answers

 const options = {
       scales: {
            xAxes: [{
                stacked: true
            }],
            yAxes: [{
                stacked: true
            }]
        }
    }

    let data ={ 
      datasets:[{
        label: 'test1',
          data :[1]
        },
        {
          label: 'test2',
          data:  [2]   
        }],
      labels:['label']
    }
    
    render(){
      return  <Bar  data={data} options={options} />
    }
like image 102
Ellen Chernilov Avatar answered Sep 21 '22 09:09

Ellen Chernilov