仅供参考,我在Highcharts论坛(http://highslide.com/forum/viewtopic.php?f=9&t=25673)上回复了相同的问题
首先,有一个使用模式填充列的想法。基本演示已发布在 Highcharts Uservoice 网站 (http://highcharts.uservoice.com/forums/55896-general/suggestions/2378007-allow-fill-patterns-for-areas-columns-plot-bands)。
您可以改进该代码以创建带有渐变填充的 SVG 图案。主要困难是支持数据更新(和动画)。因此,我们无法为渐变元素定义固定宽度。请看下面的示例代码:
Highcharts.Renderer.prototype.color = function (color, elem, prop) {
if (color && color.pattern && prop === 'fill') {
// SVG renderer
if (this.box.tagName == 'svg') {
var patternA,
patternB,
bgColor,
bgPattern,
image,
id;
id = 'highcharts-pattern-' + idCounter++;
patternA = this.createElement('pattern')
.attr({
id: id,
patternUnits: 'userSpaceOnUse',
width: '100%',
height: '100%'
})
.add(this.defs);
patternB = this.createElement('pattern')
.attr({
id: id + '-image',
patternUnits: 'userSpaceOnUse',
width: color.width,
height: color.width
})
.add(this.defs);
image = this.image(color.pattern, 0, 0, 6, 6)
.add(patternB);
bgColor = this.rect(0, 0, 0, 0, 0, 0)
.attr({
fill: color.fill,
width: '100%',
height: '100%'
})
.add(patternA);
bgPattern = this.rect(0, 0, 0, 0, 0, 0)
.attr({
fill: 'url(' + this.url + '#' + id + '-image)',
width: '100%',
height: '100%'
})
.add(patternA);
return 'url(' + this.url + '#' + id + ')';
// VML renderer
} else {
var markup = ['<', prop, ' type="tile" src="', color.pattern, '" />'];
elem.appendChild(
document.createElement(this.prepVML(markup)));
}
} else {
return base.apply(this, arguments);
}
};
此处提供现场演示:http://jsfiddle.net/Kr82z/