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 does not fit inside container when used in Angular Material Tab

See original GitHub issue

I’m submitting a …

[X] bug report
[ ] feature request
[ ] support request

Current behavior When inside a Angular Material Tab Component the Chart does not correctly fit inside the container. It does not matter if the size of the container is set to a fixed dimension (direct pixel values) or relavive (percentage).

Expected behavior The Chart should resize itself to the container

Reproduction of the problem https://plnkr.co/edit/m7V3cOa95tVx9jKiLxSR?p=preview

What is the motivation / use case for changing the behavior? Using the ngx-charts inside an angular-material app with tabs

  • ngx-charts version: 6.0.2

  • Angular version: 4.3.6

  • Browser: Chrome, Firefox, Edge (all I tested)

  • Language: TypeScript

This issue is similar but I think not equal to #474. It maybe the same cause. Since as soon as you resize the window, the chart fixes its size.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
andreisrobcommented, Jan 11, 2019

@GO3LIN, @MRMokwa, @arunkumarv31, @jamesh38

I had the same issue with my chart extending beyond the border of my mat-card. However, I also have a chart in a mat-accordion panel, and although in both cases my data arrives asynchronously, the accordion panel resizes properly and contains the chart just fine.

I discovered that the display settings for the container in the mat-accordion panel uses flex, while mat-card is simply disply: block. After overriding the mat-card css to use the same flex settings, the card expands properly to fit the chart.

Note that you may need to place the css rule in a global styles file to avoid View Encapsulation problems, in addition to !important for each of your css settings.

Here is the css rule I copied from the mat-accordion panel container and applied directly to my mat-card element (you may only need the one display: flex !important; property):

.my-flex-mat-card {
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important;
}  

 <mat-card class="my-flex-mat-card">
     chart here
 </mat-card>

Works like a charm!

10reactions
davidblumercommented, Jan 10, 2019

Just change the material-tab element to be lazy loaded.

You have to put your tab-content inside <mat-tab><ng-template matTabContent>{{yourcontent}}</ng-template></mat-tab>

Read more comments on GitHub >

github_iconTop Results From Across the Web

mat-tab-group width is not reacting to width 100% container in ...
It's not a problem with mat-tab-group, but with flexbox default settings, where flex item can't be smaller that its content.
Read more >
Tabs - Angular Material
Classes to be passed to the tab label inside the mat-tab-header container. ... Plain text label for the tab, used when there is...
Read more >
Chips | Angular Material
Chips allow users to view information, make selections, filter content, and enter data. link Static Chips. Chips are always used inside a container....
Read more >
Toolbar | Angular Material
The toolbar does not perform any positioning of its content. This gives the user full power to position the content as it suits...
Read more >
Grid list | Angular Material
Ratio: This ratio is column-width:row-height, and must be passed in with a colon, not a decimal (e.g. 4:3 ). Fit: Setting rowHeight to...
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