I'm passing data in that looks like this:

{"actualDeliveryDate":1.69605E12,"totalDeliveries":3,"onTimeDeliveries":3,"percentOnTime":100},{"actualDeliveryDate":1.6961364E12,"totalDeliveries":4,"onTimeDeliveries":4,"percentOnTime":100},{"actualDeliveryDate":1.6962228E12,"totalDeliveries":2,"onTimeDeliveries":2,"percentOnTime":100},{"actualDeliveryDate":1.6963092E12,"totalDeliveries":9,"onTimeDeliveries":7,"percentOnTime":77.78}]

In this case, I have two series, a line series for total deliveries (valueYField: "totalDeliveries", valueXField: "actualDeliveryDate") and a column series for on-time deliveries (valueYField: "onTimeDeliveries", valueXField: "actualDeliveryDate"). However, I need to throw the percentOnTime value in a global tooltip along with the valueYField data.

The tooltip creation is from an example in the AmCharts documentation:

var tooltip = am5.Tooltip.new(this._root, {});

chart.plotContainer.set("tooltipPosition", "pointer");
chart.plotContainer.set("tooltipText", "a");
chart.plotContainer.set("tooltip", tooltip);

tooltip.label.adapters.add("text", function(text, target) {
    text = "On-Time Percentage: " + chart.series.values[0].get("userData").percentOnTime + "%\n";
    var i = 0;
    chart.series.each(function(series) {
        var tooltipDataItem = series.get("tooltipDataItem");
        if (tooltipDataItem) {
            if (i != 0) {
                text += "\n";
            }
            text += '[' + series.get("stroke").toString() + ']●[/] [bold width:100px]' + series.get("name") + ':[/] ' + tooltipDataItem.get("valueY");
        }
        i++;
    });

    return text
});

As you can see, I've attempted to use the userData object that I assigned in the total deliveries line series, which looks like this:

var totalOTDLineSeries = chart.series.push(
    am5xy.LineSeries.new(this._root, {
        name: "Total Deliveries",
        xAxis: xAxis,
        yAxis: yAxis,
        valueYField: "totalDeliveries",
        valueXField: "actualDeliveryDate",
        stroke: am5.color("#53c653"),
        userData: {
            percentOnTime: "percentOnTime"
        }
    })
);

This, of course, is simply showing the literal value of "percentOnTime", as opposed to using the field in the data.

Using the userData object might not be what is needed, but I haven't found a way to access the data, so it's the latest thing I've tried. The only examples of usage that I could find are at the bottom of this doc.

0

There are 0 best solutions below