2amigos / yii2-chartjs-widget

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

Extends the ChartJs widget by dynamically setting the width of the canvas #3

Closed Pfarrer closed 9 years ago

Pfarrer commented 9 years ago

... to the width of the parent element before continuing with normal ChartJs operation

fedemotta commented 9 years ago

Hi @Pfarrer , I think I was having a similar issue like you had. I was trying to make the chart responsive. Without the height and width the chart it was showing very small. I make it work using the following setting:

 'clientOptions' => [
        'responsive' => true,
    ],

I think it is not necessary your change to the code, you can achieve the same using the responsive setting.

Cheers

Pfarrer commented 9 years ago

Can you use that with a fixed height? If I try the responsive setting, it seems to keep a fixed width/height ratio, which is not what I want.

fedemotta commented 9 years ago

If you use the responsive setting. The width and height values are automatically using percentage. In example

'options' => [
        "height"=>50,
        "width" =>100,
    ],

It means 50% and 100% of the container. Resizing the browser window only resizes the chart width (at least in the tests I made).

Pfarrer commented 9 years ago

Okay, works "good enough". It does not allow a fixed height, but the size of the chart cannot grow or shrink to strong because the responsive grid system resizes the grids before. Thanks for your help!