Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing chart size (width / height) as prop doesnt resize the chart #8

Closed
jcalonso opened this issue Sep 7, 2016 · 5 comments
Closed

Comments

@jcalonso
Copy link
Contributor

jcalonso commented Sep 7, 2016

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?

@apertureless
Copy link
Owner

apertureless commented Sep 7, 2016

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>

@jcalonso
Copy link
Contributor Author

jcalonso commented Sep 7, 2016

Thanks! it works now!. 🎉

@jin2125
Copy link

jin2125 commented Mar 6, 2017

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

@apertureless
Copy link
Owner

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

@paketaaa
Copy link

i've tryed to change props at media but my canvas didn't updated, is there any ideas?
i did this
:width="$mq === 'xs' ? 714 : 1200" :height="$mq === 'xs' ? 322 : 540"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants