How to add a single series bullet in am4charts?

229 views Asked by At

Here's my situation: a line series are being dynamically drawn and at a certain point I would like add a single series bullet. Ideally, that bullet would have an ID, by which at a later time it could be removed.

So far all my attempts led to the bullets being added to every single series data point (code below):

var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.width = 10;
bullet.height = 10;
bullet.fillOpacity = 1;
bullet.strokeWidth = 0;

I can trigger this action at any time after the chart is already created (so say after 10 data points are already drawn on it), but it still adds bullets to every single data point. I figured one of the ways could be to add them all with 0 opacity, and then update opacity on the single select bullet. However, I am not able to access a single bullet as yet, so any pointers would be appreciated. When updating it for the first time, it will be the last data point added, if that changes anything.

Lastly, their bullet documentation does mention ID parameter, but if I create it like this:

bullet.id = 'some unique long id';

...it does not get attached to anything. I hope the above information is enough to put me out of my misery. Thank you very much in advance!

1

There are 1 answers

0
SimonDau On

Ok, so here's the answer: bullets are being added to every single data point and it is not possible (to the best of my knowledge) to add a single one only. Hence add bullets with the fillOpacity = 0 and then upon adding a new value to the chart use bullet adaptor to filter the correct one(s) and update it:

bullet.adapter.add("fillOpacity", function(fill, target) {
    if (!target.dataItem) {
        return fillOpacity;
    }
    var values = target.dataItem.values;
    return values.dateX.value < new Date(2018, 3, 3)? 0: 1;
});

This was used with the DateAxis hence comparing against a date.