fxcosta / laravel-chartjs

Simple package to facilitate and automate the use of charts in Laravel 5.x using Chartjs v2 library
486 stars 112 forks source link

stacked bar chart #49

Closed ommyan closed 7 years ago

ommyan commented 7 years ago

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

fxcosta commented 7 years ago

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!

ommyan commented 7 years ago

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?

Emhc commented 7 years ago

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);
ommyan commented 7 years ago

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

fxcosta commented 7 years ago

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

ommyan commented 7 years ago

Thank you so much fellix

On Jul 19, 2017 11:38 AM, "Felix Costa" notifications@github.com wrote:

@ommyan https://github.com/ommyan @Emhc https://github.com/emhc It was a serious mistake of mine. The documentation was wrong. It has been corrected... b2b1560 https://github.com/fxcosta/laravel-chartjs/commit/b2b156076c8cdf6b7fbe82c30d11da16b53bea50

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fxcosta/laravel-chartjs/issues/49#issuecomment-316270478, or mute the thread https://github.com/notifications/unsubscribe-auth/ADhbCcJC68-gxZv2_5gA2m5z33eWtNoWks5sPYgxgaJpZM4ORlu6 .