关于前端:highcharts-04wrap

场景:
须要对每个series设置不同背景色的tooltip时,highcharts本身没有这种配置项,就须要咱们利用Highcharts原型封装函数Wrap。
wrap对现有的highcharts示例的原型进行批改,容许在现有函数之前或之后向其中增加本人的代码。

其用法如下:
(function (H) {
H.wrap(H.Tooltip.prototype, ‘refresh’, function (proceed, points) {

  // When refresh is called, code inside this wrap is executed

});
}(Highcharts));
(下面是一个立刻执行函数的写法,看外面的H.wrap)

wrap函数的第一个参数为父类对象,第二个参数为要封装的函数名称,第三个参数为回调替换函数。

咱们也能够用简略奢侈的写法
示例代码如下:
const H = Highcharts;
H.wrap(H.Tooltip.prototype, ‘refresh’, function (p, point, mouseEnents) {
p.call(this, point, mouseEnents);
const label = this.label;
if (point && label) {

label.attr({
    fill: point.series.userOptions.marker.fillColor
});

}
});

成果如下

同步更新到本人的语雀
https://www.yuque.com/diracke…

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理