Highcharts-ng Size does fill div until Inspect Element

☆樱花仙子☆ 提交于 2019-12-02 05:55:33

问题


I am adding highcharts to my Angular-Firebase app using Highcharts-NG and the highchart is not assuming the size of the div. However, when I got to inspect the element so I can custom size the chart it magically assumes the div size. I've done a search and have tried some of the fixes I have found but none work. Is this a known issue? How do I get it to size properly without inspect element?

I have a youtube video of the problem here: LINK

<div ng-show="overviewOn">
    <div class="col-md-12 text-center">
        <table class="table table-bordered">
            <thead>
                <th>Total Score</th>
                <th>Strokes Gained Putting</th>
                <th>Penalty Strokes</th>
            </thead>
            <tbody>
                <td>{{round.totalScore}}</td>
                <td>{{round.sgPutting | number:2 }}</td>
                <td>{{round.penalty}}</td>
            </tbody>
        </table>
    </div>
    <div class="col-md-12 shotTypeChart">
        <div style="width:100%;margin: 0 auto">
            <highchart id="sgShotTypeChart" config="sgShotTypeChartConfig"></highchart>
        </div>
    </div>
    <div class="col-md-12 clubChart">
        <highchart id="sgClubChart" config="sgClubsChartConfig"></highchart>
    </div>
</div>

$scope.sgClubsChartConfig = {
            options: {
                chart: {
                    type: 'column'
                },
                plotOptions: {
                    column: {
                        dataLabels: {
                            enabled: true,
                            crop: false,
                            overflow: 'none',
                            formatter: function () {
                                return Highcharts.numberFormat(this.y, 2);
                            }
                        }
                    }
                },
                tooltip: {
                    pointFormat: "Strokes Gained: {point.y:.2f}",
                    style: {
                        padding: 10,
                        fontWeight: 'bold',
                    }
                }
            },
            series: [{
                showInLegend: false,
                data: sgByClubData,
                name: 'Strokes Gained'
            }],
            title: {
                text: 'Strokes Gained by Club'
            },

            loading: false,
            yAxis: {
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: 'gray'
                    },

                },
                title: {
                    text: null
                }
            },
            xAxis: {
                categories: clubsData,
            },
            credits: {
                enabled: false
            },
            useHighStocks: false,
        };

回答1:


I've found not so delicate way to fix it. Just add these lines:

 setTimeout(function() {
                    $(window).resize();
                }, 0);


来源:https://stackoverflow.com/questions/28835572/highcharts-ng-size-does-fill-div-until-inspect-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!