I n...">

Angular HighChart in Tab Width

So, I have the following highChart tag:

<highchart id="chart1" config="chartConfig" ></highchart>

      

I now have multiple tabs on my system. it happens that the tall chart is not under the first tab.

enter image description here

Now when I click on the tab that contains the chart, the chart looks odd:

enter image description here

(You can't tell from this image, but it only uses 30% of the total width)

But resize the browser and then resize it so that the normal diagram fits it correctly inside the element (this also happens if I just open the console while I'm inside the tab):

enter image description here

I'm guessing it has something to do with the width of the element after it's created (possibly because it's in a different tab), but I'm not sure how to fix this.

I tried to put the style on a high level element so that it looks something like this: <highchart id="chart1" config="chartConfig style="width: 100%"></highchart>

However, this caused the graph to end out of frame.

My diagram configuration

    $scope.chartConfig = {
};

$scope.$watchGroup(['login_data'], function(newValues, oldValues) {

    // newValues[0] --> $scope.line
    // newValues[1] --> $scope.bar

    if(newValues !== oldValues) {
        $scope.chartConfig = {
            options: {
                chart: {
                    type: 'areaspline'
                }
            },
            series: [{
                data: $scope.login_data,
                type: 'line',
                name: 'Aktivitet'
            }],
            xAxis: {
                categories: $scope.login_ticks
            },
            title: {
                text: ''
            },
            loading: false
        }
    }
});

      

+3


source to share


2 answers


Can you try one of the following in your controller? (or possibly both!)



$timeout(function() {
    $scope.chartConfig.redraw();
});

$timeout(function() {
    $scope.chartConfig.setSize();
});

      

0


source


Calling the reflow method solved my similar problem when showing the graph in modal mode. Hope this helps others: D

Add this to your controller after $ scope.chartConfig :



$scope.reflow = function () {
  $scope.$broadcast('highchartsng.reflow');
};

      

0


source







All Articles