Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charts don't resize at all. #597

Open
toddpratt opened this issue May 23, 2017 · 6 comments
Open

Charts don't resize at all. #597

toddpratt opened this issue May 23, 2017 · 6 comments

Comments

@toddpratt
Copy link

I'm not sure if this is intended, but charts don't resize at all--not even when the parent container size changes. I don't see any documentation stating what is expected. This is true for the fiddle linked in the bug creation comments. (http://jsfiddle.net/gh/get/jquery/3.1.1/pablojim/highcharts-ng/tree/master/jsfiddles/basic/)

How can I get the chart to resize its width to the parent container and when window sizes change?

Highcharts 5.1.0, Angular 1.6.4, highcharts-ng 1.1.0

This happens on Edge on Windows and Chrome on Windows and Linux. On Firefox on Windows and Linux, all but the top ~5% of the chart is clipped (this also happens in the jsfiddle provided).

(I saw a lot of discussion about "reflow" hacks. That had no effect and those issues didn't describe what I'm seeing now.)

@thomasraynal
Copy link

thomasraynal commented May 30, 2017

Same issue here.
The dirty workaround :

$element.find("#mychart").highcharts();
 chart.setSize(width, height);

where #mychart is the directive id attribute.

Or you can add $watch on the directive itself for element.clientWidth and element.clientHeight:

HighChartNGController.$inject = ['$scope', '$element', '$timeout'];

function HighChartNGController($scope, $element, $timeout) {

 $scope.$watch(function() {
            return $element[0].clientWidth
        }, function() {
            ctrl.chart.setSize($element[0].clientWidth, $element[0].clientHeight);
        });

}

(The latter may need to make $scope.$digest() call somewhere...)

@joaocmfcm
Copy link

I have the same issue using bootstrap and Highcharts-ng. The chart is always 600x400 https://i.imgur.com/f5FP8iQ.png no matter the div's size

@wojtczal
Copy link

wojtczal commented Sep 4, 2017

Seems that you need to include highcharts-ng.css in your project. See here

@dhodgin
Copy link

dhodgin commented Oct 30, 2017

the highcharts-ng.css file also just has one css class in it. you can just paste it into your own css and it works for me without the overhead of a http load of another file for one 3 line css class.

@Zerokk
Copy link

Zerokk commented Jul 5, 2018

For me, letting the "width" property in the HighCharts object, and adding this snippet to my wrapper component, works (In Angular 5, both Chrome and Firefox Quantum):

    window.addEventListener("resize", ()=> {
      document.getElementById("mychart").style.width = "100%";
    })

Where "mychart" is the ID of the div that holds your chart.

@charliegroll
Copy link

I was going to PR this repo, but it doesn't look like anyone's been supporting it in a long time. If anyone is looking for the answer, I discovered that it's because browsers (Chrome, in my testing) treat elements that they don't know about as display: inline by default. Highcharts tries to compute the size to fill from the chart container's parent, and if it's right below an angular component, that's "computed" as 0. If you manually style it to display: block or just give the component a template with a plain block element, that allows Highcharts to compute the size correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants