score:22
(Copied from my comment.)
I can't get StackBlitz to run (JS errors due to tracking protection in Firefox) so I can't verify this, but I had that exact issue in my flex layout and solved it by ensuring overflow: hidden
was set on the parent (and ancestor) flex elements. A cursory look at your CSS shows this is only done on .page-wrapper
.
score:0
Here your canvas is having width inside absolute parents so its recommended to change the values dynamically using JavaScript (angular in your case). But since you are looking for CSS based solution here is what you can add in your app.components.css file:
.sidebar-wrapper.shrink + div.main-wrapper canvas {
width: calc(100vw - 40px) !important;
}
.sidebar-wrapper:not(.shrink) + div.main-wrapper canvas {
width: calc(100vw - 230px) !important;
}
Here is the working example : https://chartjs-overflow-ex-vlsqmn.stackblitz.io/
score:1
Update: This solution stopped working with chart.js 3
I had similar problems with a markup like this:
<div style="display: flex; flex-direction: column">
<h2>...</h2>
<div class="chart-container" style="position: relative; flex: 1">
<canvas></canvas>
</div>
<span>...</span>
<span>...</span>
</div>
My outermost div was in a css-grid, maybe that also played a role.
Anyhow, I diagnosed the problem to be this: Even though I applied { responsive: true, maintainAspectRatio: false }
to the options of chart.js, the chart had a fixed size, which caused the chart-container not to shrink (even when overflow: hidden
was applied, I don't fully understand why). This caused the div element chartjs inserts to detect size changes to never change its height.
So the solution was to simply override the height on the canvas to 100%: canvas {height: 100%!important}
.
This allows the canvas container to shrink, causing the size-detection div to shrink, causing a re-render of the canvas, which prevents aspect-ratio issues.
Source: stackoverflow.com
Related Query
- Chart.js in flex element overflows instead of shrinking
- Angularjs - Charts.js: Same chart element doesn't redraw on other view
- Chart.js bar chart is overflowing its containing element
- ChartJs bar chart - keep bars left instead of equally spread across the width
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- Chart.js bar chart mouse hovering highlights all the datasets instead of just the selected one
- Chart js logarithmic line chart showing NaN values instead of null
- Chart x axis displays in timestamp instead of dates Chart.js
- Cannot create chart on react element
- Tooltips in Chart js are always black instead of the color of the corresponding dataset
- Chart JS, ng2-Charts - How to make the label to the right of pie chart instead on top?
- Chart.js: Reverse bar chart with regular bars (Bottom to top instead of top to bottom)
- Highlight chart element when hovering over its corresponding legend Item
- Connect the dot vertically instead of horizontally on Line Chart
- Chart JS tooltip appears differently when set from script instead of html
- Chart JS stacked labels instead of making them horizontal
- How to display date instead of year in morris line chart in js
- How to clear/destroy Chart.js canvas when the chart is represented as a react JSX element
- Group bar chart in ReactChartJS2 click particular element
- Chart js pie or doughnut charts 3 inside instead of 1
- what is wrong with my code ? java script chart position
- How to print a chart rendered by code
- chart js draw line chart by points instead of by lines
- How to make a chart with a string values instead of data?
- Chart JS - Change the color of the last element in a Bar Chart
- How do i have a single Chart.vue component instead of different chart components and then display charts from it by changing id of the API
- Update of options for PrimeNG Chart needs two calls instead of one
- VueJS + Chartjs - Chart only renders after code change
- How do I destroy/update Chart Data in this chart.js code example?
- getting additional value fields from data source for dx.chartjs doughnut chart
More Query from same tag
- Chart Value of the bar
- TS how can I use a class variable inside method?
- ChartJS adding 3yAxes
- Type can not be assigned in react-chartjs-2
- Sorting the Bars in Chart.JS Bar Graph
- How to add an on click event to my Line chart using Chart.js
- How to plot dates in Chart.js
- Chart.js - Uncaught ReferenceError: chart is not defined
- Merge 2 charts into 1 chart using update button (chart.js)
- everything i put in the options of the Line charts doesnt work
- Chart.JS tooltip color doesn't works as expected in pie chart. How to solve it?
- In Stacked horizontal bar chart how to remove the vertical line in Chart.js?
- How to paint specific area of chartJs?
- Line chart not rendering data
- Dynamically update chart in chartJs
- Can't display data labels in chartJS
- Chart JS pass in custom data for points
- Auto center ticks and values on graph when there's only one with chart.js
- chart.js datapoint offset multiple charts
- Bootstrap tab is working but the tab content is not showing
- Full size download Chartjs canvas on mobile device
- How to get ChartJs object from dynamically created chart
- JavaScript doughnut chart with centered hover label
- Ng2-charts / chart.js - how to refresh/update chart - angular 4
- ChartJS non overlapping lines
- PrimeNG/Chart.js - max Number of labels to show
- How to style specific gridlines differently in chartJs?
- Fail to load chart on Flask/jinja2 html using chart.js
- Dataset legend color is not updating after changing background color of dataset and update (chartJs framework)
- Chart.js not to be begin in Y-Axis