Charts - set Tooltip format per series

384 views Asked by At

I have a use case where the client needs to see the previous date ranges stats overlaid on the current date range. This will allow them to easily compare current vs previous performance.

To do this I'm adding another series to the charts and retrieving the previous periods data. Previously, we then set the tooltip for the X value which was the current dates. I'm now needing to modify the tooltip to show the correct date value for each series such that a previous periods data point tooltip might look like:

12/1 : $4432.00

and the current periods data point:

1/1 : $21321.12

However it seems the charts are only capable of a single tooltip formatter instead of a per series formatter. If I continue to use the X axes label it will display the incorrect date on the previous periods data points. Using the above example would come out with 1/1 for the previous point:

1/1 : $4432.00

Is there a method by which I can set a tooltip format per series? Is there also any means by which we can modify and extend the underlying Highcharts?

1

There are 1 answers

0
fakataha On

I've found one solution for this function. Create a new XAxis and assign it to the Series.

XAxis xAxis = new XAxis();
xAxis.setCategories(categories);
xAxis.setOpposite(true);

configuration.addxAxis(xAxis);

series.setxAxis(1);

By adding the new XAxis the tooltip formatter can you use the same logic but receive different values depending on which axes the series is attached to.

I found setting the X axis by Integer a bit odd though. It should take the object imo but I suppose it needs to know which axis in the configuration's array to assign it to.

This solves the use case I have but won't be a solution if there are more than 2 axes to label.