【问题标题】:How can we add a tooltip on series name of Amcharts?我们如何在 Amcharts 的系列名称上添加工具提示?
【发布时间】:2020-08-11 07:46:14
【问题描述】:

如何在 Amchart 的系列名称悬停时添加工具提示。 (想要在所附屏幕截图中的选定区域上添加工具提示)。

添加一个系列名称,如:

let series = chart.series.push(new am4charts.LineSeries());
series.name = q1.seriesName;

谢谢!

【问题讨论】:

    标签: javascript angular amcharts amcharts4


    【解决方案1】:

    这是一种方法。我不知道为什么必须使用setTimeout。没有它,图表加载时values 数组为空。

    chart.legend = new am4charts.Legend();
    setTimeout(function() {
      chart.legend.itemContainers.values[0].tooltipText = 
        "The [bold {color}]{name}[/] series is awesome!";
      chart.legend.itemContainers.values[1].tooltipText = 
        "The [bold {color}]{name}[/] series is cool!";
      chart.legend.itemContainers.values[2].tooltipText = 
        "The [bold {color}]{name}[/] series is nice!";
    }, 500);
    

    【讨论】:

    • 需要超时,因为 AmCharts 异步创建所有内容。如果要在所有 itemContainers 上设置默认值,请使用模板,例如chart.legend.itemContainers.template.tooltipText = "[bold {color}]{name}[/] "。如果您在没有超时的情况下设置单个值,请改用就绪事件 (chart.events.on('ready', () => { chart.legend.itemContainers.each((container) => { container.tooltipText = "..." } ) }))。请注意,values 是只读的,不应直接操作 - 使用 eachfor ... of
    • 谢谢@Stephane。该解决方案完美运行!
    • 感谢@xorspark,我在 chart.events.on('ready', () =>{ 下添加了该代码
    猜你喜欢
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多