Vue-chartjs: Passing chart size (width / height) as prop doesnt resize the chart

Created on 7 Sep 2016  ·  4Comments  ·  Source: apertureless/vue-chartjs

Expected Behavior

The chart should of the one specified in the props

Actual Behavior

Appears to be 100% of the view port.

Environment

I'm using vueify and have something like this:

<my-chart width="300" height="300" :data="{{ json_encode($data) }}"></my-chart>

Is this the correct way to pass these properties to alter the size of the chart?

⚠️️ bug

Most helpful comment

Hi, thanks for the issue.
Yeah there was a bug with the props.

It's fixed in the current version 1.1.2

However you have to pass the width and height like this:

<my-chart :width="300" :height="300"> </my-chart>

Because the props are numerical.

And you need to disable the chartjs reponsive option.

http://www.chartjs.org/docs/#chart-configuration-global-configuration

There are two options in there, responsive and maintainAspectRatio.
By default both are set to true. But if responsive is true, the canvas container always have the full width of the outer container.

If you set responsive to false, the canvas container will stay at the width and height, which are set.

If you won't both, a fix width or max-width and responsiveness, then you can simply wrap the canvas into a div with a class.

<div class="grid grid-1-3"> 
 <my-chart></my-chart>
</div>

All 4 comments

Hi, thanks for the issue.
Yeah there was a bug with the props.

It's fixed in the current version 1.1.2

However you have to pass the width and height like this:

<my-chart :width="300" :height="300"> </my-chart>

Because the props are numerical.

And you need to disable the chartjs reponsive option.

http://www.chartjs.org/docs/#chart-configuration-global-configuration

There are two options in there, responsive and maintainAspectRatio.
By default both are set to true. But if responsive is true, the canvas container always have the full width of the outer container.

If you set responsive to false, the canvas container will stay at the width and height, which are set.

If you won't both, a fix width or max-width and responsiveness, then you can simply wrap the canvas into a div with a class.

<div class="grid grid-1-3"> 
 <my-chart></my-chart>
</div>

Thanks! it works now!. :tada:

why i set width and height, but result not i want, example: except width: 200; height: 100, but result not match except

Like exaplained in the chart.js docs you have to pass the options object with

{
responsive: false,
maintainAspectRatio: false
}

Just checkout some of the examples

Was this page helpful?
0 / 5 - 0 ratings

Related issues

syxolk picture syxolk  ·  5Comments

m-jooibar picture m-jooibar  ·  4Comments

egorzekov picture egorzekov  ·  4Comments

ihrankouski picture ihrankouski  ·  3Comments

Scalpel78 picture Scalpel78  ·  4Comments