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

Chart not responsive - width stuck at 600px no matter what I do #262

Open
tonym99 opened this issue Apr 4, 2018 · 7 comments
Open

Chart not responsive - width stuck at 600px no matter what I do #262

tonym99 opened this issue Apr 4, 2018 · 7 comments

Comments

@tonym99
Copy link

tonym99 commented Apr 4, 2018

I'm stuck with a fixed width and height of 600px and 400px respectively no matter what the browser is narrowed to. The demos all seem to be responsive, but for some reason mine is stuck at 600px.

This is the resulting div for the chart after rendering:

This is my chart definition/options:

chart: {
backgroundColor: 'transparent',
marginTop: 10,
marginBottom: 50,
animation: false,
type: 'column'
},
title: { text: null },
scrollbar: {
enabled: true
},
reflow: true,

        responsive: {
            rules: [{
                condition: {
                    maxWidth: 1000
                },
                chartOptions: {
                    legend: {
                        align: 'center',
                        verticalAlign: 'bottom',
                        layout: 'horizontal'
                    },
                    yAxis: {
                        labels: {
                            align: 'left',
                            x: 0,
                            y: -5
                        },
                        title: {
                            text: null
                        }
                    },
                    subtitle: {
                        text: null
                    }
                }
            }]
        },
        legend: {
            enabled: false,
        },
        yAxis: {
            min: 0,
            max: maxval,
            stackLabels: {
                formatter: function () { return '$' + that.currencyPipe.transform(this.total, 'USD', true, '1.0-0'); }
            },
            title: { text: null },
            labels: {
                formatter: function () { return '$' + that.currencyPipe.transform(this.value, 'USD', true, '1.0-0'); }
            }
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b>: ' + that.currencyPipe.transform(this.point.y, 'USD', true, '1.0-0');
            }
        },
        plotOptions: {
            series: {
                animation: false
            },
            column: {
                borderWidth: 0,

                stacking: 'normal',
                events: {
                    legendItemClick: function () {
                        return false; 
                    }
                }
            }
        }

Anyone??

@tonym99
Copy link
Author

tonym99 commented Apr 4, 2018

solved it -

CSS

chart{
display: block;
width: 100%;
}

@rrrroooonnnn
Copy link

rrrroooonnnn commented May 29, 2018

this seems to work if your chart isnt in a dynamic container. I have a sidebar that toggles open but the chart always remains the same size whether or not the sidenav is open or closed. the documentation doesnt give a thorough example of accessing the chart.reflow function so I've been unable to figure that out. anyone experience something similar with dynamic containers?

i just need the chart to stretch and shrink as the sidenav toggles open and closed.

@as88425
Copy link

as88425 commented May 31, 2018

@snekkysnek did u find any solutions for the same actually i also looking for the same requirement

@rrrroooonnnn
Copy link

@as88425 no not yet but i believe calling chart.reflow() is the only solution. that being said, I haven't been able to successfully do this but will update if i figure it out.

@as88425
Copy link

as88425 commented May 31, 2018

@snekkysnek i achieved the same using chart.ref.setSize(some dynamic width, some dynamic height, false) for angular 5. i thought it's also work for angular 2

@rrrroooonnnn
Copy link

@as88425 can you show me the context where you used chart.ref.setSize. that might work for me too i just dont know where/how to use it.

@as88425
Copy link

as88425 commented May 31, 2018

@snekkysnek Please see the below example

let chartMonthly = new Chart({
                chart: {
                    renderTo: '0',
                    //type: 'column',
                    // width: 508,
                    zoomType: 'x',
                    reflow: true


                },
                title: {
                    text: ''
                },
......
});

so here i defined chartMonthly as a variable
Then i am going to set the size of chart using below code

reflowchart(event) {        
        setTimeout(() => {   
            var width = Some dynamic width 
            this.chartMonthly.ref.setSize(width, 400, false);
        }
```, 300);
    }

i called `reflowchart` function on my html.

Note =>  this.chartMonthly.ref means i am accessing a.chart value which is $('#container').Highchart() from jquery method .

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

3 participants