question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to set this chart width and height ?

See original GitHub issue

my english is very poor ,sorry~

how to set this chart width and height ?

this is my code

// homechart.js
import { Line } from 'vue-chartjs'
export default Line.extend({
  props: ["data"],
  mounted () {
    this.renderChart(this.data, {

    })
  }
})

my vue app

<template>
  <homechart :data='chart'></homechart>
</template>
<script>
  import homechart from './homechart'
  export default {
    components: { homechart },
    data() {
      return {
        chart:{
          labels : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],
          datasets : [
            {
              fillColor : "rgba(220,220,220,0.5)",
              strokeColor : "rgba(220,220,220,1)",
              data : [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1]
            }
          ]
        }
      }
    },
  }
</script>

the chart is work , but ,it’s so big, i want set chart width and height.

show me the code , please , think you!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

48reactions
aperturelesscommented, Nov 14, 2016

Hey,

seems to be related to #8

There are two possibilities. If you want your chart to be responsive, you can wrap your chart into a div that has a max-width (in css) If you want a fixed width and height, you can simply pass it the props.

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

However you will need to set the repsonsive property to false. And maybe the maintainAspectRatio. Both are chartJs options you can pass in the data object.

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

20reactions
fengcmscommented, Nov 14, 2016

think you , you are so fast! it’s work now! the code is

// homechart.js
import { Line } from 'vue-chartjs'
export default Line.extend({
  props: ["data", "options"],
  mounted () {
    this.renderChart(this.data, {
      maintainAspectRatio:false
    })
  }
})

and

<homechart :width="300" :height="300" :data='chart'></homechart>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting width and height [closed] - Stack Overflow
Show activity on this post. This works. The key here is to use an outer div and set the width and height on...
Read more >
Responsive Charts - Chart.js
When it comes to changing the chart size based on the window size, a major limitation is that the canvas render size (...
Read more >
Move or resize a chart - Microsoft Support
To use specific height and width measurements, on the Format tab, in the Size group, enter the size in the Height and Width...
Read more >
Set Chart Size with ChartJS - Mastering JS
To set the chart size in ChartJS, we recommend using the responsive option, which makes the Chart fill its container.
Read more >
Limit the height and width of chart.js - CodePen
<p>Example of chart that will respect it's containers width and height via the property <code>maintainAspectRatio: false</code></p>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found