Stacked Column Highchart with Angular6 is not work

2019-07-31 17:08发布

I am trying to implement the stacked column chart for the first time with angular6 by following the Angular standard example from the link

https://www.tutorialspoint.com/angular_highcharts/angular_highcharts_column_stacked.htm

But this give me blank container on the web page. Is there anything needs to be added.

Below I am attaching my html and ts files for reference.

app.module.ts 

 imports: [
      ...
        HighchartsChartModule

    ],
.HTML file 

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto">

    <highcharts-chart
        [HighCharts]="highcharts"
        [options]="chartOptions"
    ></highcharts-chart>
</div>

.ts file 

 highcharts = Highcharts;
    chartOptions = {
        chart: {
            type: 'column'
        },
        title: {
            text: 'Monthly Average Temperature'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            verticalAlign: 'top',
            x: 250,
            y: 100,
            floating: true,
            borderWidth: 1,
        },
        xAxis: {
            categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'], title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip : {
            valueSuffix: ' millions'
        },
        plotOptions: {
            column: {
                dataLabels: {
                    enabled: true
                }
            },
            series: {
                stacking: 'normal'
            }
        },
        credits:{
            enabled: false
        },
        series: [
            {
                name: 'Year 1800',
                data: [107, 31, 635, 203, 2]
            },
            {
                name: 'Year 1900',
                data: [133, 156, 947, 408, 6]
            },
            {
                name: 'Year 2008',
                data: [973, 914, 4054, 732, 34]
            }
        ]
    };


    constructor() {
    }

    ngOnInit() {
    }

Please share your suggestions/advice.

Thanks in advance !!

1条回答
叼着烟拽天下
2楼-- · 2019-07-31 17:52

The reason to get blank at web page is below : I was adding the HighChartsChartModule import under app.module.ts which is root level. But in my project there are different modules, and each module have its own .module.ts file. So if I add HighChartsChartModule under imports for specific module then it works as expected. It never work if I just add under the app.module.ts

import { HighchartsChartModule } from 'highcharts-angular';

@NgModule({
    imports: [

        HighchartsChartModule
    ],
查看更多
登录 后发表回答