fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stacked bar chart

ommyan opened this issue · comments

really appreciate for nice plugin.

let me know, how to create a stacked bar chart, I was tried to configure options with optionraw but doesn't work.

thanks

Hi, @ommyan! I've not tested it yet but see if this works: https://stackoverflow.com/questions/37249439/chartjs-v2-0-stacked-bar-chart

pass to optionsRaw this setup and post result here, plz!

In My controller ,
`

$membershipChart = app()->chartjs
         ->name('barChartTest')
         ->type('bar')
         ->size(['width' => 400, 'height' => 200])
         ->labels(['PBU', 'PPU'])
         ->datasets([
             [
                 "label" => "Aktual",
                 'backgroundColor' => ['rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.72)'],
                 'data' => [69, 59]
                
             ],
             [
                 "label" => "Target",
                 'backgroundColor' => ['rgba(255, 99, 132, 0.3)', 'rgba(54, 162, 235, 0.93)'],
                 'data' => [65, 12]
                  
             ]
         ]);
$membershipChart ->optionsRaw = "{
            legend: {
                display:false
            },
            scales: {
                xAxes: [{
                    stacked:true,
                    gridLines: {
                        display:false
                    }  
                }]
            }
        }";

`
debuging with

dd ($membershipChart);

attached is result of debugging,

dd

optionraw failed to generate json for 'options' and chart object, any suggest for me?

commented

i had the same problem and i figured out a way to work around, might not be the best practice but hope this can help you:

$options = [];
$options['scales']['xAxes'][]['stacked'] = true;
$options['scales']['yAxes'][]['stacked'] = true;

	$chartjs = app()->chartjs
		->name('lineChartTest')
		->type('bar')
		->size(['width' => 400, 'height' => 200])
		->labels($labels)
		->datasets($data)
		->options($options);

i think this is another way to roma... :)
thank you so much

@ommyan @Emhc It was a serious mistake of mine. The documentation was wrong. It has been corrected... b2b1560