英文:
Animate startAngle in anychart sunburst chart
问题
如何在Anychart旭日图中实现起始角度的动画效果。以下是我的代码:
this.chart = anychart.sunburst(data, "as-tree");
this.chart.container(this.container.nativeElement);
this.chartDraw();
this.pointSelectChart();
this.pointHoverChart();
this.mouseDownChart();
this.chart.level(2).labels().position("circular");
this.chart.level(2).labels().hAlign("center");
this.chart.labels().useHtml(true);
this.chart
.level(2)
.labels()
.format(
"<span style='font-size:14px; word-break: break-word'>{%name}</span>"
);
this.chart
.level(1)
.labels()
.format("<span style='font-size:20px'>{%name}</span>");
this.chart
.level(0)
.labels()
.format(
"<span style='font-size:18px; text-transform: uppercase'>SUSTAINABILITY</span><br><span style='font-size:18px; text-transform: uppercase'>AT THE LME</span>"
);
this.chart.interactivity().selectionMode("single-select");
this.chart.normal();
this.chart.startAngle(320);
this.chart.contextMenu(false);
this.chart.draw();
this.generateDisclosureTable(
data[0].children[0].name,
"theme",
data[0].children[0].fill,
data[0].children[0].backgroundColor,
data[0].children[0].fontColor
);
在叶子节点上单击时,我尝试对startAngle进行动画处理。
Anychart似乎没有在旭日图上提供任何动画函数。我们如何才能实现这个效果呢?
英文:
How can we animate the startangle in Anychart sunburst chart. Below is my code:
this.chart = anychart.sunburst(data, "as-tree");
this.chart.container(this.container.nativeElement);
this.chartDraw();
this.pointSelectChart();
this.pointHoverChart();
this.mouseDownChart();
this.chart.level(2).labels().position("circular");
this.chart.level(2).labels().hAlign("center");
this.chart.labels().useHtml(true);
this.chart
.level(2)
.labels()
.format(
"<span style='font-size:14px; word-break: break-word'>{%name}</span>"
);
this.chart
.level(1)
.labels()
.format("<span style='font-size:20px'>{%name}</span>");
this.chart
.level(0)
.labels()
.format(
"<span style='font-size:18px; text-transform: uppercase;'>SUSTAINABILITY</span><br><span style='font-size:18px; ; text-transform: uppercase;'>AT THE LME</span>"
);
this.chart.interactivity().selectionMode("single-select");
this.chart.normal();
this.chart.startAngle(320);
this.chart.contextMenu(false);
this.chart.draw();
this.generateDisclosureTable(
data[0].children[0].name,
"theme",
data[0].children[0].fill,
data[0].children[0].backgroundColor,
data[0].children[0].fontColor
);
onclick of leaves I am trying to animate the startAngle.
Anychart doesn't seem to provide any animate function on sunburst chart. How could we go about to achieve this.
答案1
得分: 1
太阳图表默认情况下没有动画效果。
要创建动画效果,您可以使用 startAngle 方法并自定义函数。您可以在文档中找到有关 Sunburst startAngle 的更多信息。
我们已经准备了两个演示示例,涵盖不同的用例:
第一个演示示例展示了如何通过拖动滑块动态更改图表的角度。
// 获取滑块的DOM元素
var slider = document.getElementById("startAngleSlider")
...
...
// 通过滑块更改图表起始角度
slider.addEventListener("input", function(e){
chart.startAngle(slider.value)
})
第二个演示示例展示了如何通过点击动态更改图表的角度。
// 更新起始角度的函数
var updateStartAngle = function (endAngle)
{
// 设置更新起始角度的定时器
setTimeout(function ()
{
// 检查是否需要更新角度
if (endAngle > 0)
{
// 将图表角度增加5个单位
chart.startAngle(chart.startAngle() + 5);
// 以5个单位的差值递归调用更新函数
updateStartAngle(endAngle-5);
}
}, 5)
}
chart.listen("mouseDown", function(){
updateStartAngle(90);
})
但是,对于包含大量数据集的图表,使用这种方法可能会导致性能问题。
英文:
The sunburst chart has no animations out of the box.
To create an effect of an animation, you may utilize custom functions with the startAngle method.
You can find more information about the Sunburst startAngle in the documentation.
We have prepared 2 demos with different use cases:
The first demo shows how to dynamically change an angle of a chart by dragging the slider.
//get slider DOM element
var slider = document.getElementById("startAngleSlider")
...
...
//change chart start angle by slider
slider.addEventListener("input", function(e){
chart.startAngle(slider.value)
})
The second demo shows how to dynamically change an angle of a chart by clicking.
//update a start angle
var updateStartAngle = function (endAngle)
{
//set timeout for updating start angle
setTimeout(function ()
{
//check if there is a need to update an angle
if (endAngle > 0)
{
//update the chart by 5 angles
chart.startAngle(chart.startAngle() + 5);
//recursive call of an update function with 5 angles less goal
updateStartAngle(endAngle-5);
}
}, 5)}
chart.listen("mouseDown", function(){
updateStartAngle(90);
})
However, charts with massive data sets may cause performance issues with this approach.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论