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.

chart js flexbox width ignored

See original GitHub issue

I’m using Bulma v0.6.2 CSS framework with vue-chartjs 3.2.1, trying to put a Line chart inside a Box container. My chartjs options are all correct and as advised for achieving responsiveness:

responsive: true,
maintainAspectRatio: false

I also use a container for my chart as advised (the chart-container class property):

<UserActivity
v-bind:chart-data="datacollection"
v-bind:options="graphOptions"
class="chart-container"
/>

with the following chart-container CSS:

.chart-container {
    position: relative;
    height: 40px;
}

but it seems like the chart ignores the parent element’s width:

enter image description here

I looked around found some hints that the issue may be related to Bulma and Flexbox. Did anyone encounter this issue?

EDIT: This jsfiddle reproduces the issue https://jsfiddle.net/c6tu3qgx/1/

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
labelworxcommented, Sep 29, 2019

I had all of the symptoms detailed above but this hacky fix seems to work fine. I have 4 charts displayed in a flexbox row shrinking perfectly.

canvas { width: 100% !important; }

7reactions
phil-wcommented, Jun 25, 2018

I’ve been through the other tickets on this, but this seems to be the survivor. My example is a simple case with a full-width table with a column containing a sparkline: https://jsfiddle.net/0rg1jesx/ This is a trivial example; my purpose is to point at this defect, not to demonstrate a good way to use HTML. In live I have a Bootstrap grid with a table of data in it, and the table rows contain sparkline charts as well as other data.

The charts grow beautifully, but won’t shrink no matter what I try. Although its the same symptom as this apparent “flexbox” thing the problem persists even when the flexbox is removed. That’s not the root issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chart js flexbox width ignored - css - Stack Overflow
I'm using Bulma v0.6.2 CSS framework with vue-chartjs 3.2.1 , trying to put a Line chart inside a Box container. My chartjs options...
Read more >
Width - Tailwind CSS
Utilities for setting the width of an element.
Read more >
Flex Cheatsheet
The defining aspect of flex layout is the ability to make the flex items “flex”, altering their width/height to fill the available space...
Read more >
justify-content - CSS: Cascading Style Sheets - MDN Web Docs
The CSS justify-content property defines how the browser distributes space between and around content items along the main-axis of a flex ...
Read more >
react height 100 percent not working with flex - You.com
Making a flexbox container height 100% in react js ... CSS Flex property not working with my React Component ... chart js 2...
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