2amigos / yii2-chartjs-widget

ChartJs Widget For Yii2
https://2amigos.us
Other
108 stars 69 forks source link

Cannot create Stacked bar #37

Closed pptyasar closed 6 years ago

pptyasar commented 6 years ago

Cannot create stacked bar as in https://codepen.io/Karl53/pen/MbYrPN?editors=0010

pptyasar commented 6 years ago

My code

              `<?= ChartJs::widget([
                         'type' => 'bar',
                             'options' => [

                                ],
                'data' => [
                    'labels' => ['2016', '2017', '2018', '2019'],
                    'datasets' => [[
                        'type'=>'bar',
                        'label'=> 'a',
                        'yAxisID'=>"y-axis-0",
                        'backgroundColor' => "rgba(217,83,79,0.75)",
                        'data' => [1000, 2000, 4000, 5000]
                    ],
                    [
                        'type'=>'bar',
                        'label'=> 'b',
                        'yAxisID'=>"y-axis-0",
                        'backgroundColor' => "rgba(92,184,92,0.75)",
                        'data' => [500, 600, 700, 800]
                    ],
                     [
                         'type'=>'line',
                         'fill'=>false,
                         'label'=> 'c',
                         'yAxisID'=>"y-axis-0",
                         'backgroundColor' =>"rgba(51,51,51,0.5)",

                         'data' => [150, 200, 400, 500]
                     ],
                    [
                        'type'=>'line',
                        'fill'=>false,
                        'label'=> 'd',
                        'yAxisID'=>"y-axis-1",
                        'backgroundColor' => "rgba(151,187,205,0.5)",
                        'data' => [500, 300, 100, 0]
                    ]]
                ],
                'clientOptions' =>
                [
                    'options' => [
                        'title'=>[
                            'display' => true,
                        ],
                        'tooltips'=>[
                            'mode'=> 'label'
                        ],
                        'responsive'=> true,
                    ],

                    'scales'=> [
                        'xAxes'=> [
                            'stacked'=>true,
                        ],
                        'yAxes'=>[
                             [
                                'stacked'=>true,
                                'position'=>'left',
                                'id'=> "y-axis-0",
                             ],
                             [
                                'stacked'=>false,
                                'position'=>'right',
                                'id'=> "y-axis-1",
                             ],

                        ]
                    ],
                ],
            ]);
        ?>`
pptyasar commented 6 years ago

Worked after

changing 'xAxes'=> [ 'stacked'=>true, ],

into

'xAxes'=> [ [ 'stacked'=>true,] ],