score:46
What worked for me is calling:
$(window).resize();
When I load a new tab. Still having the issues with the Google Maps API, but it works great with Highcharts.
score:3
/**
* Adjust size for hidden charts
* @param chart highcharts
*/
function adjustGraph(chart) {
try {
if (typeof (chart === 'undefined' || chart === null) && this instanceof jQuery) { // if no obj chart and the context is set
this.find('.chart-container:visible').each(function () { // for only visible charts container in the curent context
$container = $(this); // context container
$container.find('div[id^="chart-"]').each(function () { // for only chart
$chart = $(this).highcharts(); // cast from JQuery to highcharts obj
$chart.setSize($container.width(), $chart.chartHeight, doAnimation = true); // adjust chart size with animation transition
});
});
} else {
chart.setSize($('.chart-container:visible').width(), chart.chartHeight, doAnimation = true); // if chart is set, adjust
}
}
catch (err) {
// do nothing
}
}
usage
$(window).resize(function () {
if (this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(function () {
// resizeEnd call function with pass context body
adjustGraph.call($('body'));
}, 500);
});
for bootstrap tab
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var isChart = $(this).attr('data-chart');
var target = $(this).attr('href');
if (isChart) {
// call functio inside context target
adjustGraph.call($(target));
}
});
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="active">
<a href="#anagrafica" data-toggle="tab"><h5>Anagrafica</h5></a>
</li>
<li>
<a href="#consumi" data-toggle="tab" data-chart="1"><h5>Consumi</h5></a>
</li>
</ul>
on chart
new Highcharts.Chart({
chart: {
renderTo: 'chart-bar',
defaultSeriesType: 'column',
zoomType: 'xy',
backgroundColor: null,
events: {
load: function (event) {
adjustGraph(this);
}
}
},
html code
div class="tab-pane" id="charts">
<div class="row-fluid">
<div class="span6 offset3">
<div id="myCarousel" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner chart-container">
<div class="active item">
<h3>Chart 1/h3>
<div id="bar-pod-annuale">
<div id="chart-bar" style="width:100%;margin: 0 auto"></div>
</div>
</div>
<div class="item">
<h3>Char 2</h3>
/** chart **/
</div>
<div class="item">
<h3>Char 3</h3>
/** chart **/
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</div>
</div>
See on jsfiddle http://jsfiddle.net/davide_vallicella/LuxFd/2/
score:6
You will find a lot of issues when you are trying to render things that start off using "display: none". While $(window).resize() might work in many cases, I would suggest trying to first render your page before having display: none take effect. A possible solution would be to set opacity: 0 or visibility: hidden.
The display attribute is what controls how your element will render, for instance block (100% width) or inline (fit contents). When an element has display: none, it overrides this, ultimately removing it's effective width and height until that element receives a block type.
Here is a example to demonstrate: http://jsfiddle.net/m2f3scmm/3/
<div id="log1" style="display: none;">
</div>
<div id="log2" style="visibility: hidden;">
</div>
<div id="log3" style="opacity: 0">
</div>
When you are using the "resize" hack, you are assuming the plugin or script you are using is binding to the window's resize event which is not always the case. Triggering the window.resize could also slow down rendering or cause unwanted effects (for instance, the little animation highcharts does when first rendering - which looks lame when it happens each time a tab is changed).
Source: stackoverflow.com
Related Query
- Highcharts - Hidden charts don't get re-size properly
- Why code of Horizonal line(y-axis) on a single in Highcharts get applied to all other charts integrated with Webdatarocks
- Highcharts charts don't resize properly on window resize
- Highcharts Pie charts get the selected pie id
- How to get the Div id of charts in highcharts on click of it in angular 6
- How do I get my highcharts to reduce in size when the window is resized down
- Use of DotNet HighCharts dll to make charts in code behind
- Highcharts tooltip is hidden behind other charts
- highcharts context menu hidden for small charts
- Highcharts Bubble Chart - How to get the size of the point
- HTML table as data source for highstock charts using highcharts
- highcharts zooming over line charts not working properly
- Highcharts to get Combined Bar and line charts
- How can I get proper object through loop using javascript for Bubble Charts of Highcharts
- Get notice when a Highcharts chart is change after change the window size
- Highcharts in JQuery Tabs - Resizing hidden tab code stops resizing visible tab
- Border is partially hidden on hover in Highcharts column and pie charts
- HighCharts dont get value
- HighCharts and idTabs - Charts width not setting properly
- How to get highcharts dates in the x axis?
- How can I get access to a Highcharts chart through a DOM-Container?
- Highcharts tooltip overflow is hidden
- Maximum bar width in Highcharts column charts
- Changing Highcharts font size
- How to get Highcharts X-Axis Categories starting at the left most point
- Get Highcharts Series Data after Load
- Hiding _groups_ of series in Highcharts and jQuery: how to get acceptable performance?
- Highcharts Error #16: charts not showing on the same page
- how do I get two highcharts on one page?
- Highcharts does not resize charts inside tabs
More Query from same tag
- How to apply borderRadius only for top side of Column or Bar in Highchart
- Highcharts multi y-axis min-max issue
- How to hide an element using javascript
- Highchart the horizontal gradline below the 0 axis
- Highcharts datetime starting on wrong day
- HighCharts box-plot: how to make it horizontal
- Draw charts with a Loop using HighCharts in symfony
- Creating dynamic Highcharts based on an array
- Add Annotations to time series with highcharter
- How can i use double click in Highcharts and get that data
- How can i change highcharts data values by selecting from a dropdown list
- Highcharts doesn't resize properly once expanded
- Heat map with time line
- Highcharts data loading from a JSON file error in setting up datetime
- Is there a limit on Highcharts series size?
- Add a bar independent of categories ("reference" bar)
- X axis labels on HighCharts
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- Highcharts PieChart Legend paging faulty
- Would it be possible to make sure that when a cursor hovers over a certain area, it would not change to "hand"?
- Formatting MongoDB aggregation for Highcharts Stacked Columns
- Highcarts custom legend
- Highcharts unable to handle large amount of data?
- How To Get Data From Database To Highcharts Plugin in cakephp
- Padding between X-Axis labels in Highchart
- How to Add Custom Data to Highchart.js Tooltip
- Highcharts stacked column don't show the stacked with min value
- Highcharts custom x-axis categories aligned center (Under the pins)
- How to add a line break in Highchart legend in R?
- HTML table data into arrays via jQuery