Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highstocks graph width not correctly rendered

Hello I have a problem with highstocks when using jquery tabs.

this is the code for the constructor.

Chart = new Highcharts.StockChart({  
        Chart = new Highcharts.StockChart({
        chart: {
            renderTo: 
                'Container',
                 alignticks:false
             },
        xAxis: { .......... },
        yAxis: [{ ....... }],
        series : [{ .......... }]
    });

The Container has only half the width of the whole page.

When the page is loaded to the tab containing the graph, then its width is rendered correctly. But when the page is loaded first to another tab, then its width spans the whole width of the page, overlapping with other things on the page. So the page has to be refreshed in order to fix this.

Does anyone have a solution to this?

like image 593
user1081236 Avatar asked Dec 05 '11 09:12

user1081236


2 Answers

You could also trigger the window.resize Event

$(window).trigger('resize');

And Highcharts should update the Chart size

like image 120
david Avatar answered Oct 05 '22 05:10

david


Highcharts sets the width of the chart to the width of the containing element. So if the containing element is hidden, it can't get a width.

To fix this you can set the width option when initializing your chart:

Chart = new Highcharts.StockChart({  
    Chart = new Highcharts.StockChart({
    chart: {
          renderTo: ...,
          width: <SOME WIDTH>
        },
    xAxis: { .......... },
    yAxis: [{ ....... }],
    series : [{ .......... }]
});

If you aren't able to set the chart to a proper width I've used this trick to be able to get the width of a hidden element:

jQuery: Get height of hidden element in jQuery

like image 31
Brent Dubecki Avatar answered Oct 05 '22 05:10

Brent Dubecki