Skip to content

docs: update the readme to include aspectRatio example #722

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,39 @@ watch: {
}
```

#### Responsive

If you want the chart to be responsive and to respect an aspect ratio, you have to set the `width` and the `height` props of your chart component to null after setting the `aspectRatio` in the chart `options`

Here is your chart component in it's parent template.
```vue
<template>
<MyChartComponent :width="null" :height="null"></MyChartComponent>
</template>
```

Here is the component definition
```js
import { Line } from 'vue-chartjs'

export default {
name: 'MyChartComponent',
extends: Line,
props: {
chartdata: {
type: Object,
default: null
},
},
mounted () {
const options = {
responsive: true,
aspectRatio: 1.5 // width/height
}
this.renderChart(this.chartdata, options)
}
}
```
## Examples

### Chart with props
Expand Down