Problem with multiple charts in different tabs
See original GitHub issueHi!
I’m using bootstrap for the layout and drawing multiple chats in different tabs:
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#chart1" role="tab" data-toggle="tab">Chart 1</a></li>
<li><a href="#chart2" role="tab" data-toggle="tab">Chart 2</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="chart1">
<canvas id="myChart1" width="400" height="400"></canvas>
</div>
<div class="tab-pane" id="chart2">
<canvas id="myChart2" width="400" height="400"></canvas>
</div>
</div>
With the following javascript:
$(function() {
'use strict';
var line_chart_options = {
scaleGridLineColor : "rgba(0,0,0,.05)"
};
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
}
]
};
var ctx = $("#myChart1").get(0).getContext("2d");
var myLineChart1 = new Chart(ctx).Line(data, line_chart_options);
var ctx = $("#myChart2").get(0).getContext("2d");
var myLineChart1 = new Chart(ctx).Line(data, line_chart_options);
});
But when I add responsive: true
option
var line_chart_options = {
scaleGridLineColor : "rgba(0,0,0,.05)",
responsive: true
}
it stops showing a chart in the second tab.
Is there any way to get it to work?
Thank you in advance!
Issue Analytics
- State:
- Created 9 years ago
- Comments:25 (4 by maintainers)
Top Results From Across the Web
Auto multiple graphs over different tabs - Microsoft Community
I'm trying to auto generate tabs based on unique values in a column and auto generate multiple graphs for different groups on these...
Read more >Multiple Graphs on Tabs | CanvasJS Charts
The problem may be due to rendering the chart before even tab is displayed because of which dimensions for the chart are not...
Read more >How to create a chart from multiple sheets in Excel - Ablebits
The tutorial demonstrates how to make charts in Excel from multiple sheets, and how to customize and edit such graphs.
Read more >Angular 5, Chart.js displaying multiple charts, one on each tab
I can display a single chart without problems, but I am trying to display that chart once per tab of a mat-tab-group, of...
Read more >st: Re: Problem with graphs in separate tabs (Windows) - Stata
Re: st: Re: Problem with graphs in separate tabs (Windows) ... not: > > My setting is to create multiple graphs as tabs...
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
No success with previous solutions and workarounds. No destroy(), rebuild(), clear(), redraw(), resize(), update(); reAnything() has save me. This ugly hack is the only thing that is working for me:
I have this problem if I try to render in a parent with negative margins (even when not the direct parent, and only when < -10px 🙄 ). Seems like the width is getting calculated to 0 for the canvas, but the internal chart state (
chart.chart
) thinks it has the correct size. So when you runchart.resize()
it kicks out early.I am able to force a resize by doing this immediately after chart creation: