Highcharts 文本梯度高图表Wordcloud
Wordcloud highcharts现在在其最新版本(>=6.0)中可用,现在我对文本上的梯度(线性/径向)布局感到困惑。例如,在本例中,如果我将series对象中的颜色数组更改为Highcharts 文本梯度高图表Wordcloud,highcharts,word-cloud,Highcharts,Word Cloud,Wordcloud highcharts现在在其最新版本(>=6.0)中可用,现在我对文本上的梯度(线性/径向)布局感到困惑。例如,在本例中,如果我将series对象中的颜色数组更改为 fillColor: { linearGradient: [0, 0, 0, 200], stops: [ [0, 'white'], [1, 'black'] ] }, 它什么也不做 Wordcloud功能有限,但我无法完
fillColor: {
linearGradient: [0, 0, 0, 200],
stops: [
[0, 'white'],
[1, 'black']
]
},
它什么也不做
Wordcloud功能有限,但我无法完成这项任务。甚至尝试为不同的文本渐变添加多个def(k是介于0到n之间的值)
并通过
fill:url(#myLinearGradient_k)搜索类并应用css填充此myLinearGradient_k代码>。但它非常笨重。此外,在这种情况下,不可能按id进行搜索,唯一的可能是附加到类highcharts point,这限制了选项。您可能会发现此实时演示有帮助:
在chart.events.load
中,我放置了负责查找最大权重、创建渐变(每个点都有一个单独的渐变)并应用它们的代码:
chart: {
events: {
load: function() {
var points = this.series[0].points,
renderer = this.renderer,
maxWeight = 0;
// find maximum weight
points.forEach(function(p) {
if (p.weight > maxWeight) {
maxWeight = p.weight;
}
});
points.forEach(function(p, i) {
var id = 'grad' + i;
// create gradient
var gradient = renderer.createElement('linearGradient').add(renderer.defs).attr({
id: id,
x1: "0%",
y1: "0%",
x2: "100%",
y2: "0%"
});
var stop1 = renderer.createElement('stop').add(gradient).attr({
offset: "0%",
style: "stop-color:rgb(255,255,0);stop-opacity:1"
});
var stop2 = renderer.createElement('stop').add(gradient).attr({
offset: Math.round(p.weight / maxWeight * 100) + "%",
style: "stop-color:rgb(255,0,0);stop-opacity:1"
});
// apply gradient
p.update({
color: 'url(#' + id + ')'
}, false);
});
this.redraw();
}
}
}
API参考:为了不让我误解,你想要这个渐变做什么?基于X轴位置?基于体重?所有文本都有相同的渐变?基于权重的渐变。e、 g.如果relv weigt为4/10,则相应地为停止点。因此,调用所有负载是一种方式,感谢您的响应。
chart: {
events: {
load: function() {
var points = this.series[0].points,
renderer = this.renderer,
maxWeight = 0;
// find maximum weight
points.forEach(function(p) {
if (p.weight > maxWeight) {
maxWeight = p.weight;
}
});
points.forEach(function(p, i) {
var id = 'grad' + i;
// create gradient
var gradient = renderer.createElement('linearGradient').add(renderer.defs).attr({
id: id,
x1: "0%",
y1: "0%",
x2: "100%",
y2: "0%"
});
var stop1 = renderer.createElement('stop').add(gradient).attr({
offset: "0%",
style: "stop-color:rgb(255,255,0);stop-opacity:1"
});
var stop2 = renderer.createElement('stop').add(gradient).attr({
offset: Math.round(p.weight / maxWeight * 100) + "%",
style: "stop-color:rgb(255,0,0);stop-opacity:1"
});
// apply gradient
p.update({
color: 'url(#' + id + ')'
}, false);
});
this.redraw();
}
}
}