是的,有一个解决方法。您可以通过使用 jQuery 的 attr() 函数来实现这一点。当您单击矩形时,您会更改 stroke-width 属性。
我仍然认为这可能是作为 API 的错误报告的好点吗?
无论如何,JS 代码将如下所示:
$(function () {
var renderer = new Highcharts.Renderer(
$('#container')[0],
400,
300
),
rect = renderer.rect(100, 100, 100, 100, 5)
.attr({
'stroke-width': 2,
stroke: 'gray',
fill: 'silver',
zIndex: 3
})
.on('click', function () {
rect.animate({
x: 50,
y: 50,
width: 200,
height: 20
})
$("rect").attr("stroke-width", "30"); // here you can change the stroke-width
})
.add();
});
要在这里看到它的实际效果,调整后的JSFIDDLE
第 2 版
根据您的评论,我编辑了代码。在这种情况下,您还为笔画宽度设置了动画。这是一个简单的解决方案。另一种解决方案是调整我不推荐的原始 Highcharts 库。无论如何,希望它有所帮助:
$(function () {
var renderer = new Highcharts.Renderer(
$('#container')[0],
400,
300
),
rect = renderer.rect(100, 100, 100, 100, 5)
.attr({
'stroke-width': 2,
stroke: 'gray',
fill: 'silver',
zIndex: 3
})
.on('click', function () {
rect.animate({
x: 50,
y: 50,
width: 200,
height: 20
})
$("rect").animate(
{ "stroke-width": "10" },
{
duration: 500,
step: function(now) { $(this).attr("stroke-width", now); }
});
})
.add();
});
可以将持续时间调整为适合您的时间。
在此处查看实际操作:JSFIDDLE