score:0
I had a jQuery accordion that was opening with garbled charts... this was my solution:
first is stuffed the charts in a global: window.myNamespace.charts.#{container_id}, and then in my accordion i do this:
$('#my-accordion').accordion
...,
change: () ->
chartId = ui.newContent.find('.highcharts-container').parent().attr('id')
window.myNamespace.charts[chartId].setSize(248,220) if chartId?
the above is coffeescript, but it should be easy enough to translate...
basically i'm calling setSize on the chart to set it to the size it already is... this has the effect of cleaning up the chart after it opens... which i'll admit is just a workaround... ideally highcharts fixes the bug and uses the size i'm giving them instead of trying to calculate the size from a hidden element
score:0
Hi see my fiddle jsfiddle
...
$("#tabs").tabs();
var ids = ['chart-1', 'chart-2', 'chart-3'];
for (var i = 0, j = ids.length; i < j; i++) {
if ((container = $('#'+ids[i])).size()) {
if (container.width()==0) {
container.width(container.actual('width'));
}
oclone = $.extend({}, options);
oclone.chart.renderTo = ids[i];
new Highcharts.Chart(oclone);
}
}
...
score:0
I had a similar issue in that my charts were rendering on the client with zero width whenever the chart was on a tab that was not activated by default. This answer was inspired by ojreadmore's answer. Instead of using the document ready event of jQuery to initialize your highchart, you should instead use the activate event of your the tab your chart is on. This has the added benefit of doing the snazzy chart animation each time the user clicks the tab.
Instead of:
$(document).ready(function() {
var chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
});
});
Use:
$('#tabcontainer').on('tabsactivate', function (event, ui) {
var chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
title: {
text: 'Fruit Consumption'
},
xAxis: {
categories: ['Apples', 'Bananas', 'Oranges']
},
yAxis: {
title: {
text: 'Fruit eaten'
}
},
series: [{
name: 'Jane',
data: [1, 0, 4]
}, {
name: 'John',
data: [5, 7, 3]
}]
});
});
score:0
jQuery UI 1.9+ changed the way tabs are hidden, you should set your own classes when activating tabs this way:
$('#tabs').tabs({
beforeActivate: function (event, ui) {
$(ui.oldPanel).addClass('ui-tabs-hide');
$(ui.newPanel).removeClass('ui-tabs-hide');
}
});
combined with the following CSS:
.ui-tabs-hide {
display: block !important;
height: 0!important;
width: 0!important;
border:none!important;
}
This will also fix any Flash embedded object not loading properly in hidden tabs.
score:0
I ran into same problem, the reflow() method works for me. I grasp the corresponding chart by access the global Highcharts variable. Here the order of charts is order of tabs.
<script type="text/javascript">
$(function () {
$("#tabs").tabs({
show: function (event, ui) {
var chart = Highcharts.charts[ui.index];
if (chart != null) {
chart.reflow();
}
}
});
});
</script>
score:0
add class="chart"
to all highcharts containers inside tabs.
add this jQuery code:
jQuery(document).on( 'shown.bs.tab', 'a[data-toggle="tab"]', function () {
$( '.chart' ).each(function() {
$(this).highcharts().reflow();
});
})
score:0
This worked for me after adding the class name (contains-chart) in the tabs
jQuery(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) { // on tab selection event
jQuery(".contains-chart").each(function () { // target each element with the .contains-chart class
var chart = jQuery(this).highcharts(); // target the chart itself
chart.reflow() // reflow that chart
}
score:1
Smaller workaround is using a static width for your charts (if you know what it should be) in CSS-
.tab-pane { width: 1200px; }
score:2
The best solution is in callback function of tabs or when click on each tab, reflow highchart. Look at it:
Chart.reflow and this link jsfiddle and also this code that you have add in tab callback:
$('#chart-1').highcharts().reflow();
score:3
You should manually trigger resize event
$(window).trigger('resize');
score:4
The second chart may be off because it sounds like it is hidden when you draw it. Try to draw the chart upon selection.
Here is some pseudo code to give you an idea of what I imagine. This is not tested.
$("#tabs").tabs({
select: function(event, ui) {
var chart = new Highcharts.Chart({
chart: {
renderTo: ui.panel.id,
// blah blah
}
});
}
});
score:6
Modification needed in order to make Highcharts work in hidden jQuery tabs. By default, jQuery sets display: none to hidden tabs, but with this approach Highcharts is unable to get the true width and height of the element. So instead, we position it absolutely and move it away from the viewport.
<style type="text/css">
.ui-tabs .ui-tabs-hide {
position: absolute;
top: -10000px;
display: block !important;
}
</style>
adding example: http://www.highcharts.com/studies/jquery-ui-tabs.htm
score:12
This is my solution (only tested in Safari and Firefox). It works great if you want to load the chart into a hidden tab on a page with flexible width. The chart resize if the browser window is resized.
In the chart settings, set the width of the chart from the tab that opens on page load (using jQuery to get the width):
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
width: $('#tab-1').width()
},
....
The following function adjusts width if the browser window is resized. 500 is the height. This is done automatically if the width is not specified in the chart options.
$(window).resize(function() {
chart.setSize($('#chart_tab').width(),500);
});
Source: stackoverflow.com
Related Query
- jQuery UI Tabs and Highcharts display/rendering issue
- Highcharts in JQuery Tabs - Resizing hidden tab code stops resizing visible tab
- JQuery UI tabs and multiple Highcharts
- How to display the value instead of percentage in a pie chart using jquery Highcharts
- Highcharts jQuery rendering problem - all browsers
- Loading Highcharts via shim using RequireJS and maintaining jQuery dependency
- Highcharts data series issue with ajax/json and PHP
- Highcharts / jQuery - destroy and rebuild chart with original options
- How do you increase the performance of highcharts chart creation and rendering
- Highcharts Pie Chart ignores percentageDecimals tooltip setting and has floating point inaccuracy issue
- Highcharts - best way to handle and display zero (or negative) values in a line chart series with logarithmic Y axis
- display content on highcharts Xaxis and Yaxis title in form of subscript and superscript
- highcharts and canvg scaling issue
- Ajax and Highcharts - Display 'loading' until data is retrieved, then populate chart
- Highcharts - Display only year in x axis and stop auto formatting
- HighCharts Rendering Issue In Chrome
- Highcharts zoom issue after upgrading to jQuery 1.8
- Highcharts v3.0.1 problems with rotating data labels in IE8 and jQuery v1.7.1
- Highcharts - Global configuration with common code and unique data & Headings
- Simple bar chart in jQuery HighCharts and MVC 2 application?
- HighCharts performance issue and alternative
- Rails collecting and rendering JSON data in to a Highcharts graph
- Highcharts doesn't expand <div> to proper height in Chrome/Safari and doesn't display at all in Firefox
- display pie chart using highcharts api and mysql
- JQuery mobile and highcharts integration
- Highcharts - synchronized-charts crosshair line and circle point display
- how to display 2 same highcharts without duplicate the code
- Highcharts more and highcharts guage issue
- Why do I have the issue 'property assigment expected' when I want to display a chart on my web page using highcharts
- Performance issue with Firefox on Highcharts and Highstocks
More Query from same tag
- How to send an image in C# to client using async method
- Arearange highchart
- Highcharts - add custom information to tooltip what caused price raise or price drop
- highstocks x-axis time incorrect
- Unable to plot two piechart using Highchart
- Set ECG paper-like grid intervals (highcharts.js)
- Highcharts - Display Stack Label
- Highcharts width exceeds container div on first load
- Trouble parsing XML into JSON - Javascript
- HighCharts navigator and range scale not working?
- Highcharts pie rendering in conflict with legend
- Angular 7 - Dynamic HighChart update
- How to add a separate marker(an arrow) under a line
- Highcharts yAxis setExtremes far off
- Highcharts - align columns to gridlines when using series timestamps
- Export option not visible in Highcharts
- How could i put a highcharts funnel to rotate 90deg
- The tooltip is cut off in Highcharts 3.X
- Render Highcharts canvas as a PNG on the page
- PhantomJS with embedded web server uses only one CPU
- Remove underline for Drilldown labels
- Angular Highchart multiple values in tooltip
- Highchairs fill in the inside of the chart on a different background color
- Displaying multiple Highcharts from single json
- How to align centre a custom label in highcharts
- Class 'ConsoleTVs\Charts\Facades\Charts' not found in laravel Charts
- How to configure Highcharts so that it displays some pre-defined value
- Highcharts polar outcome is line instead of polar
- Highcharts CSS styling missing in exporting context button
- Tooltip doesn't show properly in highcharts