Chart does not resize inside shadow DOM (e.g. Polymer)
See original GitHub issueExpected Behavior
The Bar Chart should resize when the window size is changed.
Current Behavior
The wrapper div does resize, but the Chart does not.
Steps to Reproduce (for bugs)
https://stackblitz.com/edit/polymer310-testcase-chartjs
import '../../../node_modules/chart.js/dist/Chart.js'
class BarChartElement extends PolymerElement {
static get template() {
return html`
<style include="shared-styles2">
#content{
height: 100%;
width: 100%;
}
</style>
<div id="content"></div>
`;
}
ready(){
super.ready();
let iCan = document.createElement('canvas');
iCan.id = 'temp';
this.$.content.appendChild(iCan);
setTimeout(function () {
let ctx = (this.$.content.firstElementChild);
this.chart = new Chart(ctx, {
type: 'bar',
data: {
datasets: [{
backgroundColor: color,
data: data,
}],
},
options: {
responsive: true,
maintainAspectRatio: true,
legend: {
display: false,
},
tooltips: {
enabled: false,
},
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: 'Wochen',
fontSize: 16,
},
ticks:{
stepSize:1,
autoSkip: false,
},
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Auslastung in %',
fontSize: 16,
},
}]
}
}
});
}.bind(this), 1);
}
}
window.customElements.define('bar-chart', BarChartElement);
Environment
- Chart.js version: 2.7.2
- Browser name and version: Chrome(latest)
- Link to your project: https://stackblitz.com/edit/polymer310-testcase-chartjs
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14 (9 by maintainers)
Top Results From Across the Web
Outside styles not overriding Shadow DOM styles
Try putting box-shadow inside --app-drawer-content-container . This is working for me: app-drawer { z-index: 3; ...
Read more >Shadow DOM concepts - Polymer Project
Shadow DOM is a new DOM feature that helps you build components. You can think of shadow DOM as a scoped subtree inside...
Read more >The Shadow DOM. From Web Components in Action by…
When the component is resized or collapsed/hidden and shown again, these list elements are destroyed and then redrawn using the internal data ...
Read more >plotly-plot documentation - GitHub Pages
js library fails for all plotly plots rendered inside a shadow DOM, whether by Polymer or any other means. The element cannot tell...
Read more >Shadow DOM - W3C
Table of Contents ... Shadow DOM Example; A. Acknowledgements; B. References ... A shadow root is not a child node of the shadow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jwillmer one caution on that is that it only fires if the whole page resizes, but it won’t fire if the div containing the chart resizes.
In the meantime, I was able to get the Chart to resize inside the Shadow DOM with this snippet: