加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 更新图表中的数据,使用angular,highcharts-ng更新

发布时间:2020-12-17 10:33:58 所属栏目:安全 来源:网络整理
导读:尝试使用angular,highcharts-ng的highcharts指令. https://github.com/pablojim/highcharts-ng 我在更新数据时遇到了一些问题.更新系列值没有问题.但是我无法更新X轴标题.我在这里有一个js-fiddle http://jsfiddle.net/user1572526/3stqK/2/ 我的工厂里有cha
尝试使用angular,highcharts-ng的highcharts指令. https://github.com/pablojim/highcharts-ng

我在更新数据时遇到了一些问题.更新系列值没有问题.但是我无法更新X轴标题.我在这里有一个js-fiddle http://jsfiddle.net/user1572526/3stqK/2/

我的工厂里有chartConfig:

myapp.factory('Chart',function () {
    var chartConfig = {
        options: {
            chart: {
                type: 'column'
            }
        },series: [{
            data: [10,15,12,8,7]
        }],xAxis: [{
            categories: ['old bar title','old bar title 2 ']
        }],title: {
            text: 'Hello'
        },loading: false
    }
    return chartConfig;
});

然后我在我的控制器中公开它:

myapp.controller('myctrl',function ($scope,Chart) {
    $scope.chartConfig = Chart;

最后是一个设置一些新值的函数

$scope.update = function () {
     $scope.chartConfig.title.text = "Setting new title"; //Works    
    $scope.chartConfig.series = [{ //Works
        "name": "Updated data","data": [1,2,4,7,3]
    }];
    $scope.chartConfig.xAxis = [{ //NOT WORKING
        categories: ['new bar title','new bar title2']
    }]
    console.log($scope.chartConfig);
}

一切都有效,除了X轴.

知道这里有什么不对吗?

xAxis应该是一个对象而不是一个数组.配置应该像这样设置:
xAxis: {
        categories: ['old bar title','old bar title 2 ']
    }

更新应该是:

$scope.chartConfig.xAxis.categories = ['new bar title','new bar title2'];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读