I am using amcharts 4 to display temperature lines. At times there are many stations so I would like to have just one tooltip and just for the value the cursor is at instead of one tooltip for every line (because then they overlap and some are unreadable).
And there might be several stations with the same temperature so I would have to list all of them in the tooltip.
Anyone knows how to achieve that?
In amcharts 3 I used a balloonFunction attached to the graphs to create my own tooltip. But yet I couldn't find how to do it with the series in amcharts 4.
Thanks for a hint!
So as David Liang mentioned, since all the data items converge along their x axis value (a datetime in this case), you can limit tooltips down to one by only setting one series'
tooltipText
, and it will have access to the rest of the data fields via data placeholders. E.g. even thoughseries1
'svalue
field isE852_t4m
, it can useseries30
's value by just putting"{median_tBel}"
.But if you want to have a tooltip based on which line you're hovering over, how to do that depends whether or not you require the Chart Cursor.
If you don't need it, simply set the
tooltipText
on the line's bullets, e.g.Here's a demo of your fiddle with that:
https://codepen.io/team/amcharts/pen/803515896cf9df42310ecb7d8d7a2fb7
But if you require Chart Cursor, unfortunately there isn't a supported option at the moment. There's a kind of workaround but it's not the best experience. You start with doing the above. The Chart Cursor will trigger hover effects on all lines and their bullets, including triggering their tooltips. A bullet's tooltip is actually its series' (
series1.bulletsContainer.children.getIndex(0).tooltip === series1.tooltip
). If we remove the reference to the bullet's tooltip, e.g.series1.bullets.getIndex(0).tooltip = undefined;
, the chart will check up the chain and refer to series' anyway. If we do the same to the series'tooltip
, it'll go up the chain tochart.tooltip
, if we do this to all series, we basically turnchart.tooltip
into a singleton behavior of sorts. But it's not as responsive to mouseovers.You'll see what I mean with this demo:
https://codepen.io/team/amcharts/pen/244ced223fe647ad6df889836da695a8
Oh, also in the above, you'll have to adjust the chart's tooltip to appear on the left/right of bullets with this:
Edit:
Since the first method sufficed, I've updated it with an adapter that checks for other fields in range. In the adapter, the
target
will be theCircleBullet
,target.dataItem.valueY
is the currently hovered value, andtarget.dataItem.dataContext
are the other fields at the same date.This is how I modified
tooltipText
to show other series within +/-0.5C range of the currently-hovered bullet:If your series' data points have different x values, it's impossible to combine all the information into one tooltip.
But if they do have same x values, you can just turn on the tooltip for just one of the series:
And within the tooltip HTML, you have access to the data:
demo: http://jsfiddle.net/davidliang2008/aq9Laaew/286519/