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 chart fixed height?

See original GitHub issue

I want to make a fixed height bar chart .

This is the code :

<template>
  <h2>Bar Chart</h2>
  <div style="height: 700px">
    <vue3-chart-js v-bind="{ ...barChart }" />
  </div>
</template>

<script>
import Vue3ChartJs from "@j-t-mcc/vue3-chartjs";

export default {
  name: "App",
  components: {
    Vue3ChartJs,
  },
  setup() {
    const barChart = {
      type: "bar",
      options: {
        min: 0,
        max: 100,
        responsive: true,
        plugins: {
          legend: {
            position: "top",
          },
        },
        scales: {
          y: {
            min: -100,
            max: 100,
            ticks: {
              callback: function (value) {
                return `${value}%`;
              },
            },
          },
        },
      },
      data: {
        labels: ["VueJs", "EmberJs", "ReactJs", "AngularJs"],
        datasets: [
          {
            label: "My First Dataset",
            backgroundColor: ["#1abc9c", "#f1c40f", "#2980b9", "#34495e"],
            data: [40, 20, 50, 10],
          },
          {
            label: "My Second Dataset",
            backgroundColor: ["#2ecc71", "#e67e22", "#9b59b6", "#bdc3c7"],
            data: [-40, -20, -10, -10],
          },
        ],
      },
    };

    return {
      barChart,
    };
  },
};
</script>

I already try to set the height to 700px

<div style="height: 700px">
  <vue3-chart-js v-bind="{ ...barChart }" />
</div>

But it’s not working, chart height doesn’t change at all.

How to set bar chart fixed height?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
J-T-McCcommented, Oct 16, 2021

Sorry, pretty busy these days.

I have added fixed width and height properties. They must be used with options.responsive: false

    const lineChart = {
      type: 'line',
      height: 200,
      width: 500,      
      options: {
        responsive: false
      },
      data: {
        // ...
      },
    }

If you are using responsive charts and you want your chart to conform to the parent container dimensions you can try using options.maintainAspectRatio: false,

0reactions
ras24commented, Oct 16, 2021

@J-T-McC thank you very much for your help, it’s working now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set height of chart in Chart.js - javascript - Stack Overflow
I created a container and set it the desired height of the view port (depending on the number of charts or chart specific...
Read more >
Is it possible to make charts a fixed height? #3384 - GitHub
To get a fixed height and variable width chart… remove width or height attributes from the canvas element. set the desired css height...
Read more >
Chart.js chart with fixed height and variable width - CodePen
Chart.js chart with fixed height and variable width. Adjust the width of the window to test.
Read more >
How to Set Dynamic Height for Bar Chart in Chart js - YouTube
How to Set Dynamic Height for Bar Chart in Chart jsIn this video we will cover how to set dynamic height for bar...
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 >

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