0

I'm actually working in page which contains some stats and I got an issue with highcharts. It's been 2 hours that I'm searching solution on internet and don't find any.

First problem, I use bootstrap 3, so my container is col-xs-6 wide. In my documents, this is about 350px wide. The chart keeps rendering at 600px wide.

I found the method reflow() of course, and it works when I execute it manually into the console of FF but I tried to execute it like that and doesn't work.

function getContents(courses, user) {
    $.ajax({
        url: BeginUrl + 'analyse/get/content',
        type: "post",
        data: {courses: courses, user_id: user},
        beforeSend: function (request) {
            return request.setRequestHeader('X-CSRF-Token', $('meta[name="_token"]').attr('content'))
        },
        error: function (data) {
            swal("Oops", data.error.message, "error");
        },
        success: function (data) {
            if (data.success) {
                //update bar about content
                $('#hero-bar').html('');
                $('#hero-bar').highcharts({
                    chart: {
                        renderTo: 'hero-bar',
                        type: 'column',
                        events:{
                            load: function() {
                                this.reflow();
                            }
                        }
                    },
                    credits: {
                        enabled: false
                    },
                    legend: {
                        enabled: false
                    },
                    title: {
                        text: null
                    },
                    xAxis: {
                        categories: data.contents.categories,
                        crosshair: true
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: ''
                        }
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size:12px">{point.key}</span><table>',
                        pointFormat: '<tr>' +
                        '<td style="padding:0"><b>{point.y}</b></td></tr>',
                        footerFormat: '</table>',
                        shared: true,
                        useHTML: true
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.1,
                            borderWidth: 0
                        }
                    },
                    series: data.contents.series
                });
            }
        },
        complete: function() {
            $('#loader-content-box').fadeOut(400, function(){
                $('#content-box').fadeIn(400);
            });
        }
    });
}

I tried in events params when I'm building my chart and i tried manually in "complete" from the ajax with : $('#hero-bar').highcharts().reflow();

Both didn't worked of course.... When manually in the console, it works. I guess this is something related to the loading and render of the chart but even in the events load which seems to be executed after the chart rendering doesn't work either. Of course, I could make a fixed value to width but I need it to be responsive.

Second problem which is certainly binded to the first, When I'm resizing my window, 2 of my chart simply disappear like I called destroy method... no more <rect> or anything in my container. It does that with the previous example and the following one :

function getDeployement(courses, user) {
    $.ajax({
        url: BeginUrl + 'analyse/get/deployement',
        type: "post",
        data: {courses: courses, user_id: user},
        beforeSend: function (request) {
            return request.setRequestHeader('X-CSRF-Token', $('meta[name="_token"]').attr('content'))
        },
        error: function (data) {
            swal("Oops", data.error.message, "error");
        },
        success: function (data) {
            if (data.success) {
                //update bar line
                $('#hero-graph').html('');
                $('#hero-graph').highcharts({
                    credits: {
                        enabled: false
                    },
                    chart: {
                        renderTo: 'hero-graph',
                        height: 320,
                        width: 710
                    },
                    title: {
                        text: null,
                    },
                    legend: {
                        enabled: false
                    },
                    xAxis: {
                        categories: data.deployement.categories
                    },
                    yAxis: {
                        title: {
                            text: 'No. Participants'
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    series: data.deployement.series
                });
            }
        },
        complete: function() {
            $('#loader-deployement-box').fadeOut(400, function(){
                $('#deployement-box').fadeIn(400);
            });
            getFacilitators(courses, user);
        }
    });
}

I searched for a long time and didn't find anything that can fix it.

Anyone has an idea or already got that problem?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • Check similiar topics: http://stackoverflow.com/questions/16838758/highcharts-graph-width-is-incorrect-when-scrollbar-is-present-in-bootstrap-flui / http://stackoverflow.com/questions/17206631/why-are-bootstrap-tabs-displaying-tab-pane-divs-with-incorrect-widths-when-using / http://stackoverflow.com/questions/19516284/highcharts-item-width-not-100-in-carousel – Sebastian Bochan Jan 12 '16 at 13:25
  • @SebastianBochan Fixed my width problem but not my disappear prob. Thanks anyway ^^ I still can't figure out why it disappear on resizing... – David Sprauel Jan 13 '16 at 08:39
  • Could you recreate your second problem as live demo on jsfiddle.net (for example with hardcoded data) ? – Sebastian Bochan Jan 15 '16 at 12:42

1 Answers1

0

First problem resolved with

 $('#hero-bar').highcharts({
                    chart: {
                        renderTo: 'hero-bar',
                        type: 'column',
                        events:{
                            load: function(){
                                var c = this;
                                setTimeout(function() {
                                    $('#hero-bar').highcharts().reflow();
                                }, 500);
                            }
                        }
                    },
                    credits: {
                        enabled: false
                    },
                    legend: {
                        enabled: false
                    },
                    title: {
                        text: null
                    },
                    xAxis: {
                        categories: data.contents.categories,
                        crosshair: true
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: ''
                        }
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size:12px">{point.key}</span><table>',
                        pointFormat: '<tr>' +
                        '<td style="padding:0"><b>{point.y}</b></td></tr>',
                        footerFormat: '</table>',
                        shared: true,
                        useHTML: true
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.1,
                            borderWidth: 0
                        }
                    },
                    series: data.contents.series
                });

But still have the second one, which is really weird. Any idea?

  • Hello @David, did you fix your second problem? I'm facing mostly te same issue on http://stackoverflow.com/questions/42577448/highcharts-redraw-not-redrawing-data . Still working on it, can't make the charts being painted. – JorgeGRC Mar 06 '17 at 11:09