yii2-chartjs-widget icon indicating copy to clipboard operation
yii2-chartjs-widget copied to clipboard

Type doughnut & options

Open peresz opened this issue 8 years ago • 9 comments

After upgrade chartjs to latest version I have problem with defining width and height of chart.

$chart = ChartJs::widget([ 'type' => 'doughnut', 'options' => [ 'id' => 'cstat', 'cutoutPercentage' => 25, 'legend' => [ 'display' => false], 'height' => 150, 'width' => 150 ], 'data' => $dt, ]);

I see that options: cutoutPercentage, height, width not works. Is there any problems or I have to do it in other way?

peresz avatar Jul 26 '16 08:07 peresz

I've found solution, here result:

$chart = ChartJs::widget([
        'type' => 'doughnut',
        'options' => [
                'id' => 'cstat',
                'width' => 155,
                'height' => 155,
        ],
        '**clientOptions**' => [
                'responsive' => false,
                'legend' => [ 'display'=> false ],
                'cutoutPercentage' => 45,
                'animation' => [
                        'animateRotate' => false,
                        'animateScale' => true,
                        'duration' => 369,
                ],
        ],
        'data' => $dt,
]);

peresz avatar Jul 26 '16 10:07 peresz

Thanks @peresz

tonydspaniard avatar Jul 26 '16 19:07 tonydspaniard

Thanks for the great code 2amigos and all. I was not able to find a suitable sample in the docs so here is mine :

<?= ChartJs::widget([
    'type' => 'line',
    'data' => [
        'labels' => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        'datasets' => [
            [
                'label' => 'level',
                'data' => [0, 1, 2, 3, 4, 6, 5, 12 , 17, 50, 100],
            ]
        ],
    ],
    'options' => [
        'height' => 200,
        'width' => 500,
    ],
    'clientOptions' => [
        'title' => [
            'display' => true,
            'text' => 'Chart from the absolute beginner: definitive edition (remastered)'            
        ],
        'scales' => [
                'yAxes' => [
                    [
                        'scaleLabel' => [
                            'display' => 'true',
                            'labelString' => 'level'
                        ]
                    ]
                ],
                'xAxes' => [
                    [
                        'scaleLabel' => [
                            'display' => 'true',
                            'labelString' => 'time spent'
                        ]
                    ]
                ]
        ],
    ]
]);?>

I cannot stress enough to take very close attention to brackets and which array to put in the options: clientOptions[] or options[].

Thank you for the cool widget. Keep up the good work !

razoramon avatar Mar 17 '17 13:03 razoramon

@razoramon Thanks... I'll update the widget soon and its docs.

tonydspaniard avatar Jul 05 '17 05:07 tonydspaniard

Hi I am stuck here can you please help me out ??

<?php echo ChartJs::widget([
    'type' => 'pie',
    'data' => [
        'labels' => ["test","test1","test2","Test3"],
        
        
        'datasets' => [
            [
                'label' => 'level',
                'data' => [10,20,30,40],
                'backgroundColor' => "blue",
                
            ],
        ],
    ],
    'options' => [
        'height' => 200,
        'width' => 500,
    ],
  
]);?>

Here how can i set separate color for every parts test, test1, test2, test3 respectively green,yellow,blue and red ??

shashanbk avatar Dec 07 '17 15:12 shashanbk

Hey there,

'backgroundColor' => ['blue', 'red', 'yellow', 'green'],

I must admit that is not so evident.

Hope this helps.

razoramon avatar Dec 08 '17 14:12 razoramon

Hey there,

Thank you for your help :)

Thanks again.

On Fri, Dec 8, 2017 at 7:36 PM, razoramon [email protected] wrote:

Hey there,

'backgroundColor' => ['blue', 'red', 'yellow', 'green'],

I must admit that is not so evident.

Hope this helps.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/2amigos/yii2-chartjs-widget/issues/19#issuecomment-350271119, or mute the thread https://github.com/notifications/unsubscribe-auth/AE957VtBppwSPV2J4r9k696LEag6s9Zoks5s-UKAgaJpZM4JU5tQ .

shashank shah

shashanbk avatar Dec 08 '17 15:12 shashanbk

Is there a way to show the values of bar graph bars directly on the chart? I need to do this for printout purposes.

compugator2 avatar Feb 16 '18 14:02 compugator2

`'datasets' => [ [ 'label' => 'level', 'data' =>$recurance_reservation , 'backgroundColor' => ['blue', 'red', 'yellow', 'green','Brown','DarkMagenta','GreenYellow','Violet','DodgerBlue','Tomato','Orange','MediumSeaGreen','SlateBlue','DarkViolet ','DarkSlateGrey','blak'],

        ],
    ],`

cosoftmoh avatar Aug 05 '18 14:08 cosoftmoh