Highcharts图表事件加载不适用于wordcloud

时间:2018-04-04 14:46:20

标签: jquery highcharts

我正在用highcharts构建一个项目但是我遇到了word cloud中加载事件的问题,当wordcloud加载时它永远不会被触发/注册。这是JSfiddle的一个例子。

var lines = text.split(/[,\. ]+/g),
data = Highcharts.reduce(lines, function (arr, word) {
        var obj = Highcharts.find(arr, function (obj) {
        return obj.name === word;
    });
    if (obj) {
        obj.weight += 1;
    } else {
        obj = {
            name: word,
            weight: 1
        };
        arr.push(obj);
    }
    return arr;
}, []);
console.log(data);
console.log(lines);

Highcharts.chart('container', {
series: [{
    type: 'wordcloud',
    data: data,
    name: 'Occurrences'
}],
title: {
    text: 'Wordcloud of Lorem Ipsum'
},
events: {
load: function () {
    alert("hello");
}
}});

以下是Jsfiddle的链接:http://jsfiddle.net/2oq4njb3/10/ 因此,当wordcloud加载

时,警报永远不会被触发

1 个答案:

答案 0 :(得分:2)

根级别没有事件对象,它位于图表对象中。 https://api.highcharts.com/highcharts/chart.events

Highcharts.chart('container', {
  series: [{
    type: 'wordcloud',
    data: data,
    name: 'Occurrences'
  }],
  title: {
    text: 'Wordcloud of Lorem Ipsum'
  },
  chart: {
    events: {
      load: function() {
        alert("hello");
      }
    }
  },
});

http://jsfiddle.net/2oq4njb3/13/