我正在尝试解决Highcharts wordcloud的问题,我不知道如何才能实现这一目标。使用Highcharts提供的示例作为他们的wordcloud我想根据他们的重量不同的颜色。所以,让我们说如果我有一个重量/重复大于2的单词,我希望这些单词是绿色的。我想出了这段代码,但它没有用。
var chart = Highcharts.chart('container', {
series: [{
type: 'wordcloud',
data: data,
name: 'Occurrences'
}],
title: {
text: 'Wordcloud of Lorem Ipsum'
}
});
console.log(chart);
for(var i = 0; i < data.length; i++) {
if (chart.userOptions.series[0].data[i].weight > 2) {
chart.userOptions.series[0].data[i].name.colors = ['green'];
}
}
以下是Jsfiidle网址:http://jsfiddle.net/Lfznzsof/15/
答案 0 :(得分:1)
请尝试这个:
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;
if(obj.weight > 2){
obj.color= "green";
}
} else {
obj = {
name: word,
weight: 1,
//color: "red"
};
arr.push(obj);
}
return arr;
}, []);
console.log(data);
var chart = Highcharts.chart('container', {
series: [{
type: 'wordcloud',
data: data,
name: 'Occurrences'
}],
title: {
text: 'Wordcloud of Lorem Ipsum'
}
});
console.log(chart);
这是JSFiddle:http://jsfiddle.net/Lfznzsof/81/
希望这有帮助!