在AnyChart太阳图表中动画startAngle。

huangapple go评论77阅读模式
英文:

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, &quot;as-tree&quot;);

this.chart.container(this.container.nativeElement);

this.chartDraw();

this.pointSelectChart();

this.pointHoverChart();

this.mouseDownChart();

this.chart.level(2).labels().position(&quot;circular&quot;);
this.chart.level(2).labels().hAlign(&quot;center&quot;);
this.chart.labels().useHtml(true);
this.chart
  .level(2)
  .labels()
  .format(
    &quot;&lt;span style=&#39;font-size:14px; word-break: break-word&#39;&gt;{%name}&lt;/span&gt;&quot;
  );
this.chart
  .level(1)
  .labels()
  .format(&quot;&lt;span style=&#39;font-size:20px&#39;&gt;{%name}&lt;/span&gt;&quot;);
this.chart
  .level(0)
  .labels()
  .format(
    &quot;&lt;span style=&#39;font-size:18px; text-transform: uppercase;&#39;&gt;SUSTAINABILITY&lt;/span&gt;&lt;br&gt;&lt;span style=&#39;font-size:18px; ; text-transform: uppercase;&#39;&gt;AT THE LME&lt;/span&gt;&quot;
  );
this.chart.interactivity().selectionMode(&quot;single-select&quot;);
this.chart.normal();
this.chart.startAngle(320);
this.chart.contextMenu(false);
this.chart.draw();
this.generateDisclosureTable(
  data[0].children[0].name,
  &quot;theme&quot;,
  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(&quot;startAngleSlider&quot;)
...
...
//change chart start angle by slider
slider.addEventListener(&quot;input&quot;, 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 &gt; 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(&quot;mouseDown&quot;, function(){
 updateStartAngle(90);
 })

However, charts with massive data sets may cause performance issues with this approach.

huangapple
  • 本文由 发表于 2023年6月15日 13:55:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定