1

我正在尝试在我的角度应用程序中使用 highcharts-ng。我从来没有使用过高图表,这让我有些痛苦......

我正在尝试为我的图表创建一个指令。我知道图表已经是一个指令,但我希望将它放在一个指令中,这样我就可以更轻松地将数据从我的数据库加载到它们中,因为我每页会有几个。

该图表显示了正确的数据,但显示为折线图而不是条形图。高度变量都没有转化为图表。

我在下面附上了一张当前结果的照片。[注意它不是一个 100px 高的条形图]

错误的东西ff

angular.module('app').directive('forcastChart', function () {
return {
    restrict:'E',
    scope: {},
    templateUrl: '<highchart config="chartConfig"></highchart>',

    link: function ($scope, element, attrs) {

        $scope.title="CHAFRT?"

        $scope.chartConfig = {
            options: {
                chart: {
                    type: 'bar'
                }
            }, 
            series: [{
                showInLegend: false,
                data: [10, 15, 12]
            }],
            xAxis: [{
                categories: ['a','b','c']
            }], 
            size: {
               height: 100
            },
            title: {
                text: null  
            },
            loading: false,
            chart: {
                type: 'columns'
            }
        }
    }//end of link
}});
4

2 回答 2

4

如果您在指令控制器中而不是在链接函数中设置配置,它会起作用并保留类别 -请参阅 fiddle。不知道为什么,我想这与 highcharts-ng 库如何与父指令范围交互有关。

angular.module('app', ['highcharts-ng']).directive('forcastChart', function () {
return {
    restrict:'E',
    scope: {},
    template: '<highchart config="chartConfig"></highchart>',

    controller: function($scope, $element){
       $scope.title="CHAFRT?"

        $scope.chartConfig = {
            options: {
                chart: {
                    type: 'bar'
                }
            }, 
            series: [{
                showInLegend: false,
                data: [10, 15, 12]
            }],
            xAxis: [{
                categories: ['a','b','c']
            }], 
            size: {
               height: 100
            },
            title: {
                text: null  
            },
            loading: false,
            chart: {
                type: 'columns'
            }
        }
    }
}});
于 2015-07-31T08:32:59.800 回答
2

利用

 series: [{
              type:'bar',
              data: [10, 15, 12]
            }]
于 2015-07-30T22:00:29.663 回答