Amcharts提示 – 如何操作tooltipText?

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

Amcharts tooltip - how to manipulate the tooltipText?

问题

我有一个日期图表,我想要在每个工具提示中添加词语“今天”,如果它的日期是当前日期,但我不确定如何使用{valueY}关键字,因为它是一个引用....

假设我正在创建一个名为checkForCurrentDate()的函数,我应该如何在.tooltipText关键字中使用它?

series.tooltipText = "{dateX}: [b]{valueY}[/] this.checkForCurrentDate(???)";

代码示例

英文:

I have a chart of dates and i want to add the word "Today" to each tooltip that it's day is the current day, but i'm not sure how to use the {valueY} key since it's a reference....

Suppose i'm creating a function called checkForCurrentDate(), how can i use it in the .tooltipText key?

  series.tooltipText = "{dateX}: [b]{valueY}[/] this.checkForCurrentDate(???)";

codepen

答案1

得分: 1

我认为你应该在创建数据时调用该函数,像这样:

chart.data = [{
  "date": new Date(2023, 0, 16),
  "value": 450,
  "value2": 362,
  "value3": 699,
  "isToday": checkForCurrentDate(new Date(2023, 0, 16)),
}]

然后,你可以在你的工具提示中使用它:

series.tooltipText = "{dateX}: [b]{valueY}[/] {isToday}";

通过在创建数据对象时直接传递checkForCurrentDate函数的结果,你可以确保isToday属性基于日期包含了正确的值。

英文:

I think you should call the function when you create the data, like this:

chart.data = [{
  "date": new Date(2023, 0, 16),
  "value": 450,
  "value2": 362,
  "value3": 699,
  "isToday": checkForCurrentDate(new Date(2023, 0, 16)),
}]

Then, you can use it in your tooltip:

series.tooltipText = "{dateX}: [b]{valueY}[/] {isToday}";

By passing the result of the checkForCurrentDate function directly when creating the data object, you ensure that the isToday property contains the correct value based on the date.

huangapple
  • 本文由 发表于 2023年6月18日 18:50:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500153.html
匿名

发表评论

匿名网友

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

确定