score:-1
for me, i set chart width:
$('#container').highcharts({
chart: {
backgroundcolor: 'white',
**width:3000**,
..... }
and in html set overflow:auto
<div id="container" style="**width:100%;overflow:auto**;" ></div>
score:-1
i struggled with this for way too long, and found a solution that works for me. a little bit of background on my setup:
- the highcharts chart was loading on a tab on my website that is not visible upon logging into the site.
- when switching to that tab, the chart was well outside the div.
so, i attached a unique id to that particular tab, we'll call it tab5
, and then bound a click function that forced - and this is the important part - the <svg>
element within the container div to 100% using jquery:
$('#tab5').bind('click', function() {
$('#container_div svg').width('100%');
});
...and my sanity has been restored. for the moment.
score:-1
please add width:100%
to chart container.
hope this will resolve overflow:hidden
related issue.
classname{min-height:450px;width: 100%;}
score:0
try and encapsulate the highchart generation inside a pageshow event
$(document).on("pageshow", "#hg_graph", function() {...});
score:0
i resolved this problem (for my case) by ensuring that the containing ui elements render before the chart, allowing highcharts to calculate the correct width.
for example:
before:
var renderchart = function(){
...
};
renderchart();
after:
var renderchart = function(){
...
};
settimeout(renderchart, 0);
score:0
i have been having this issue too, and the .highcharts-container css solution wasn't working for me. i managed to solve it for my case by splitting out an ng-class condition (which was setting different widths for the container div) into separate divs.
eg, this
<div ng-class="condition?'col-12':'col-6'">
<chart></chart>
</div>
into
<div ng-show="condition" class="col-12">
<chart></chart>
</div>
<div ng-show="!condition" class="col-6">
<chart></chart>
</div>
i couldn't really tell you why it worked though. i'm guessing the ng-class takes longer to calculate the container width and so highcharts renders first with an undefined width? hopefully this helps someone anyway.
score:0
i also have the same issue in my app where i am using angular and i also using ngcloak directive which i have removed as i don't need it
after doing this my problem is solved.
score:0
i have just seen that sometimes there are several issues going on at the same time.
if it happens the height exceed the expected heigh:
scss style:
.parent_container{
position:relative;
.highcharts-container{position: absolute; width:100% !important;height:100% !important;}
}
if the width exceeds the container (bigger than what's supposed to) or does not resize properly to smaller one:
let element = $("#"+id);
element.highcharts({...});
// for some reason it exceeds the div height.
// trick done to reflow the graph.
settimeout(()=>{
element.highcharts().reflow();
}, 100 );
the last one happened to me when destroying the chart and creating a new one... the new one was coming with width extra size.
score:0
i have been also bump into this issue. both affected in desktop and mobile view of the chart.
in my case i have a chart that update the series color depending on min or max.after updating the points, the highcharts width exceeds container div on its first load.
to fix that, what i did is add chart.reflow(); after the update of points.
code:
//first declare the chart
var chart = $('#topplayer').highcharts();
//set the min and max
var min = chart.series[0].datamin; //top losser
var max = chart.series[0].datamax; //top winner
for (var i = 0; i < chart.series[0].points.length; i++) {
if (chart.series[0].points[i].y === max) {
chart.series[0].points[i].update({
color: 'green',
});
}
if (chart.series[0].points[i].y === min) {
chart.series[0].points[i].update({
color: 'red',
});
}
}
// redraw the chart after updating the points
chart.reflow();
hope this helps to those who has the same issue like me. :)
score:0
here's a solution that worked for me ! the charts were working fine for a while and then after a feature they started exceeding their container. turns out it was the defer attribute on the script in the head of my application.
try removing defer on your javascript tags:
<script defer src="script.js"></script>
to
<script src="script.js"></script>
or moving my stylesheet link higher in the head also seemed to fix it but it's a less reliable solution..
score:0
this may have been introduced since the op in 2013, but you should be able to set height with chart.height
(https://api.highcharts.com/highcharts/chart.height)
options: {
chart: {
type: 'bar',
height: window.innerheight + 'px',
},
title: {
text: 'top 10 users',
},
subtitle: {
text: 'by scores',
},
this is a web based solution, but i would expect you could cater it to jquery.mobile
score:0
none of the answers helped me. i dynamically change chart data and the top answer solution ruins the animations and causes a jump in the chart position.
the workaround that i finally came up with was to set some padding for the chart wrapper element (in my case some part of the chart to left was hidden, so i gave some left padding), and then set the chart main element overflow property to visible. it works and the animations are just fine. you may need some experimenting with padding value to get it perfectly displayed.
<div class="chart-wrapper">
<!-- high charts main element here -->
</div>
and the style
.chart-wrapper{
padding-left: 20px;
}
.chart-wrapper > div:first-child{
overflow: visible !important;
}
score:1
i just ran into the same problem today - not on mobile, but with a window sized small on first page load. when the page loads, the chart is hidden, then after some selections on the page, we create the chart. we have set a min-width and max-width for the container in css, but not a width.
when the chart is being created, it needs to determine the dimensions to create the svg . since the chart is hidden, it cant get the dimensions properly so the code clones the chart container, positions it off-screen and appends it to the body so that it can determine the height/width.
since the width is not set, the cloned div tries to take as much space as it can - up to the max-width that i had set. the svg elements are created using that width, but added to the chart container div which currently is smaller (based on the size of the screen). the result is that the chart extends past the container div's boundaries.
after the chart has rendered the first time, the on-screen dimensions are known and the clone function is not called. this means that any window resizes, or reloading of the chart data cause the chart to size correctly.
i got around this initial-load problem by overriding the highcharts function clonerenderto
which clones the div to get dimensions:
(function (h) {
// encapsulated variables
var absolute = 'absolute';
/**
* override clonerenderto to get the first chart display to fit in a smaller container based on the viewport size
*/
h.chart.prototype.clonerenderto = function (revert) {
var clone = this.rendertoclone,
container = this.container;
// destroy the clone and bring the container back to the real renderto div
if (revert) {
if (clone) {
this.renderto.appendchild(container);
h.discardelement(clone);
delete this.rendertoclone;
}
// set up the clone
} else {
if (container && container.parentnode === this.renderto) {
this.renderto.removechild(container); // do not clone this
}
this.rendertoclone = clone = this.renderto.clonenode(0);
h.css(clone, {
position: absolute,
top: '-9999px',
display: 'block' // #833
});
if (clone.style.setproperty) { // #2631
clone.style.setproperty('display', 'block', 'important');
}
doc.body.appendchild(clone);
//sa: constrain cloned element to width of parent element
if (clone.clientwidth > this.renderto.parentelement.clientwidth){
clone.style.width = '' + this.renderto.parentelement.clientwidth + 'px';
}
if (container) {
clone.appendchild(container);
}
}
}
})(highcharts);
i saved this function in a separate script file that loads after the highchart.js script has loaded.
score:2
the best way is to call chart.reflow in render event function documentation;
highcharts.stockchart( 'chartcontainer', {
chart: {
events: {
render: function() {
this.reflow();
}
},
zoomtype: 'x',
...
},
and remember to set min-width to zero and overflow to hidden in chart container.
#chartcontainter {
min-width: 0;
overflow: hidden;
}
score:3
i had a similar issue with centering the highcharts graph it gave. it would center and size correctly for some resolutions but not all. when it didn't, i had the exact same symptoms you're describing here.
i fixed it by attaching/overriding additional css to the highcharts default.
so in a custom css file, adding
.highcharts-container{
/** rules it should follow **/
}
should fix your issue. assuming that your div "hg=graph" has nothing but highcharts.
score:3
for those using angular and custom-built components, remember to define a dimensioned display
in css (such as block
or flex
) for the host element.
and when the chart container has padding, you might find this indispensable:
html
<chart (load)="saveinstance($event.context)">
...
</chart>
ts
saveinstance(chartinstance: any) {
this.chart = chartinstance;
settimeout(() => {
this.chart.reflow();
}, 0);
}
otherwise the chart will bleed past the container on load and get its correct width only at next browser reflow (eg. when you start to resize window).
score:4
define the highcharts inside the document ready:
<div style="width:50%" id="charts">
and the script:
$(document).ready(function(){
$(#chart).highcharts(){
...
});
)};
hope it works ;)
score:6
set width of the chart. that's the only option that worked for me.
chart: {
type: 'line',
width: 835
},
score:13
i have the same problem, in my case had a graph of highchart that it is shown after click a button. i put $(window).resize();
after show event and it solved the problem correctly. i hope you serve.
score:33
this works like magic
put in your css file following
.highcharts-container {
width:100% !important;
height:100% !important;
}
score:45
to call chart.reflow()
helped me.
docs: http://api.highcharts.com/highcharts#chart.reflow
Source: stackoverflow.com
Related Query
- Highcharts width exceeds container div on first load
- Highcharts exceeds the container in chrome
- Highcharts reflow is not updating Highcharts container width
- Make single bar in highcharts the width of the container
- highcharts: internet explorer ignores width of my div container
- How to render Highcharts to div with id as container - Angular?
- Highcharts container wider than parent div
- HIghcharts - chart width not the size of the parent container
- Highcharts width flow out of parent div
- Highcharts : using same div to load a chart multiple times with different series data
- Highcharts - applying background image to container div
- Highcharts 's width is not correctly rendered at a hidden div
- How to create a div container for a highcharts graphic by means of code?
- highcharts first and last category width
- Highcharts not rendering plotbands correctly on first load
- highcharts append to highcharts container div
- Highcharts error 19 issue when adjusting container width that chart displays in
- Putting select element to div with z-index position to Highcharts container
- Highcharts - issue about full chart width
- HighCharts - Make the pie chart 100% of the div
- Maximum bar width in Highcharts column charts
- HighCharts full width issue
- Fixed y-axis label width in Highcharts
- Get Highcharts Series Data after Load
- HighCharts load data via ajax
- Highcharts Solid Gauge Width
- set width of chart, highcharts
- Load data into Highcharts with Ajax
- Get Highcharts width
- Hide first yAxis label in Highcharts
More Query from same tag
- How to change Highcharts xAxis label color individually?
- highcharts half pie container too big
- Fetch data from firebase firestore and plot histogram using highcharts when cardview clicked - android
- highcharts legend overlapping
- how to draw column with value=0 in highcharts
- How to set default zoom to 6 months using highcharts-react?
- Add buttons in chart of Highcharts at runtime
- highcharts symbols without connected lines
- Datalabels is getting hidden outside the svg container in Sunburst Highchart
- Trying to Fade out all other Columns when a user selects one column
- Highcharts shared tooltip requires different valueSuffix and varying decimals
- Highcharts: Align multiple charts in same container
- how do I edit/customize tooltip
- Setting highcharts datalabels backgroundColor with the same color of its piechart series
- add scatter points on line chart, Highcharts
- Getting callback is not a function in JS with Highcharts
- Highcharts draggable glitchy tooltip
- Updating point color with data grouping
- Hichcharts - Custom legend css not getting displayed in Print Chart download functionality
- How to make label in highcharts area graph display absolute values instead of negative values?
- Getting coordinates of chart on selecting plot in highcharts
- Highcharts: Corner radius for plot border
- Adding Maplines in HighMaps using geojson file
- Highcharts: basic column chart not showing correct color
- Highcharts loading all data with xaxis simplified
- Highcharts label format with tickPositioner in a datetime x Axis
- Highcharts using JSON – Border and label colors
- Highcharts: overlapped columns in exported chart
- Scrolling over highcharts graph
- HighchartsJS getting data from URL and pass it to series data