highcharts-ng显示加载时加载图像

时间:2016-04-05 05:25:14

标签: angularjs highcharts highcharts-ng

我正在尝试使用加载对象

来设置加载功能
$scope.highchartsNG = {
        options: {
            chart: {
                type: 'bar'
            }
        },
        series: [{
            data: [10, 15, 12, 8, 7]
        }],
        title: {
            text: 'Hello'
        },
        loading: true,

    }

我已经这样做但这不起作用。

除此之外我还想显示加载以显示图像如下jsfiddle http://jsfiddle.net/86nuH/

如果我遗失了任何东西,请告诉我。

提前致谢

2 个答案:

答案 0 :(得分:0)

我怀疑你正在使用这个directive

文档说$ scope.chartConfig有一个属性options,类似于highcharts highChartsConfig

我不得不稍微改变一下属性。

这是更新的Codepen

控制器:

var myapp = angular.module('myapp', ["highcharts-ng"]);
myapp.controller('myctrl', function ($scope) {

$scope.addPoints = function () {
    var seriesArray = $scope.highchartsNG.series
    var rndIdx = Math.floor(Math.random() * seriesArray.length);
    seriesArray[rndIdx].data = seriesArray[rndIdx].data.concat([1, 10, 20])
};

$scope.addSeries = function () {
    var rnd = []
    for (var i = 0; i < 10; i++) {
        rnd.push(Math.floor(Math.random() * 20) + 1)
    }
    $scope.highchartsNG.series.push({
        data: rnd
    })
}

$scope.removeRandomSeries = function () {
    var seriesArray = $scope.highchartsNG.series
    var rndIdx = Math.floor(Math.random() * seriesArray.length);
    seriesArray.splice(rndIdx, 1)
}

$scope.options = {
    type: 'line'
}

$scope.swapChartType = function () {
    if (this.highchartsNG.options.chart.type === 'line') {
        this.highchartsNG.options.chart.type = 'bar'
    } else {
        this.highchartsNG.options.chart.type = 'line'
    }
}
$scope.toggleLoading = function () {
    $scope.highchartsNG.loading = !$scope.highchartsNG.loading
}
 $scope.highchartsNG = {
     options: {
         chart: {
             type: 'bar'
          },
        loading: {
        labelStyle: {
        fontWeight: 'bold', position: 'relative', top: '45%'
        },
       style :{
        backgroundImage: 'url("http://jsfiddle.net/img/logo.png")',
            opacity:0.5,
            backgroundRepeat:'no-repeat',
            backgroundSize:'cover',
            position: 'absolute',
             width: '100vw',
             height:'100'
       } 
    },
    lang :{
        loading:'Loading...'
    }
    },
    series: [{
        data: [10, 15, 12, 8, 7]
    }],
    title: {
        text: 'Hello'
    },
    loading: false
}

 });

答案 1 :(得分:0)

为什么不在这里设置加载:

options: {
  chart: {
    type: 'bar',
    events: {
      load: function () {
         this.showLoading(); // show loading message/image
      }
    }
  },
  // set options:
  loading: {
    labelStyle: {
      top: '45%',
      backgroundImage: 'url("http://jsfiddle.net/img/logo.png")',
      display: 'block',
      width: '136px',
      height: '26px',
      backgroundColor: '#000'
    }
  }
}