echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Display the nearest data of different series in one tooltip.

Open RomanOlegovich opened this issue 3 years ago • 34 comments

What problem does this feature solve?

Is there a way to show the nearest data of different series in one tooltip?

Several series with a common x-axis are displayed on the chart. Although the time between values may differ, I would like to display a general hint if the time difference is no more than a few seconds. There can be about 8 series on the chart, a series of 30k - 100k points long, it is large dataset to dynamic search nearest data on tooltip formatter, also dynamic search is very slow. Store nearest data for each point is bad way also it's slow too.

Chart options: The x-axis is time, the y-axis is value.

Series 1: [{x: 1 ms}, {x: 3 ms}, {x: 5 ms}]
Series 2: [{x: 0 ms}, {x: 2 ms}, {x: 6 ms}]

What does the proposed API look like?

May be

tooltip: {
    nearest: true,
    formatter: (params: Object|Array, nearest: Object|Array) =>
}

RomanOlegovich avatar Aug 06 '21 02:08 RomanOlegovich

Hi! We've received your issue and please be patient to get responded. 🎉 The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to [email protected]. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list.

Have a nice day! 🍵

echarts-bot[bot] avatar Aug 06 '21 02:08 echarts-bot[bot]

Are you using 'axis' for trigger? Does snap work for you? It may probably show series with the exact x value rather than nearby data of all series as you expected. I'm not sure if this will confuse the user to think that all series have the exact x value but in fact not?

Ovilia avatar Aug 09 '21 07:08 Ovilia

Hi @Ovilia . Yes I use 'axis' trigger. I'm not sure what do "snap", but it doesn't work for me. Can snap threshold be configured to show nearby data of all series? Here example of series, which should be in one tooltip. 128958427-48410a72-cfb4-4356-8925-4e75f29142ff

RomanOlegovich avatar Aug 11 '21 01:08 RomanOlegovich

Is it possible with current library implementation?

RomanOlegovich avatar Aug 13 '21 01:08 RomanOlegovich

No, it is not supported yet. Because we believe this will mislead the user to believe the second series also share the x value of the tooltip position. If you need to implement this, you can get the x value with event and use a for loop to calculate the nearest value in each series and set to the tooltip formatter.

Ovilia avatar Aug 13 '21 03:08 Ovilia

We could consider providing an extra option to enabled this new feature. To be discussed later.

Ovilia avatar Aug 13 '21 03:08 Ovilia

@Ovilia Also issue exists: after sampling not all series with same x-axis will display on single tooltip. May be current issue is connected.

RomanOlegovich avatar Aug 16 '21 04:08 RomanOlegovich

Hello I am giving a +1 on this. Typically I use Echarts to display time series from sensors and they don't emit values at the same time. The tooltip is quite useless and get flicky if time difference are not the same between data series : https://jsfiddle.net/x035faqe/2/ axisPointer.snap: true do not seems to change something. I think it could be nice to have an option to get a tooltip that is constantly showing all series in it with the nearest value. Maybe an option to seek series' nearest point with a limit of n seconds to not display value n seconds far from each others in the same tooltip.

Raphyyy avatar Nov 11 '21 16:11 Raphyyy

@Raphyyy Thanks for reporting. We are going to work on axisPointer.snap in the near future.

Ovilia avatar Nov 12 '21 00:11 Ovilia

Nice thanks! I think the actual implementation of axisPointer.snap if true is to magnet the axisPointer to the nearest point, no matter the series. The approach here is a bit different. The purpose is not to magnet axisPointer to the nearest point, it's to read all series' nearest point to get them in the tooltip, so I don't know if it is related to axisPointer.snap at the end.

Raphyyy avatar Nov 12 '21 11:11 Raphyyy

+1 for this

RndRss avatar Nov 23 '21 13:11 RndRss

+1 for this too

petrjahoda avatar Nov 25 '21 16:11 petrjahoda

+1 continuous reading of all series values at any x point would be nice - even if it's interpolated when there is no real value for a series at this x.

Wintermute79 avatar Jan 28 '22 18:01 Wintermute79

+1 to this too! I just wrestled with this issue for days-worth of "spare time" until I finally generated some test data to realize what was causing my tooltip to not display as intended. I'm also using echarts to show time series from sensors, which never emit data at the exact same time.

I would like this feature very much (forcing tooltip to display all series to the nearest timeslot on hover).

If library managers are so concerned with misleading the viewer, one possibility would be to also display the timestamp for each series on the tooltip, instead of just the one. However, I would be happy if the tooltip just displayed the time where it was triggered, or the time of the first series it reads, or just about anyting.

Methodician avatar Feb 11 '22 14:02 Methodician

Found a workable work-around for folks in a similar situation to me...

My sensors emit data every 5 minutes, so I'm rounding the time to the nearest 5 minutes and it works like a charm. I map through the readouts for each sensor to create my series. Here is some example code to get you started:

modulesWithReadouts.map(({ name, readouts }) => { const series: SeriesOption = { name, type: 'line', data: readouts.map((readout: any) => { const coeff = 1000 * 60 * 5; // 5 minutes return [ new Date(Math.round(readout.timestamp / coeff) * coeff), readout.temperature, ]; }), }; return series; });

Methodician avatar Feb 11 '22 15:02 Methodician

The workaround from @Methodician might be viable in cases when you know the sampling frequency beforehand. However, in more general cases when your data is of various sampling rate it unfortunately does not work. Some datasets don't have a data point that would round to a specific point on the x axis while other datasets can round down to the same x multiple times.

See the screenshot for an example of such scenario. image

So, +1 from me for being able to snap the tooltip to the nearest point within a given margin of error.

P.S. Kudos to echarts for gracefully handling this weird yet peculiar edge case :)

P.S. 2: Turns out I already filed a feature request for the exact same thing more than a year ago :) https://github.com/apache/echarts/issues/13389

l1b3r avatar Feb 18 '22 09:02 l1b3r

For anyone who might be interested, I found a workaround that works for me. Here's the link to the stackoverflow answer (explanation + code) : https://stackoverflow.com/questions/55238820/how-can-i-show-all-series-in-tooltip-when-series-does-not-have-same-time-values/72026277#72026277

If a series doesn't have a value at a given x, the tooltip displays the closest value (actual series point) : image

It could also display the value that we see along the line (not an actual point then), by modifying the function with a linear interpolation. image

leomerel avatar Apr 27 '22 11:04 leomerel

It could also display the value that we see along the line (not an actual point then), by modifying the function.

How? that is the actual question. You did not provide that function code which gives you 23.9 from 2nd image above.

Wintermute79 avatar Apr 27 '22 12:04 Wintermute79

How? that is the actual question. You did not provide that function code which gives you 23.9 from 2nd image above.

I just added the code I wrote to achive that result in the stackoverflow answer. Hope it'll help !

leomerel avatar Apr 27 '22 13:04 leomerel

How? that is the actual question. You did not provide that function code which gives you 23.9 from 2nd image above.

I just added the code I wrote to achive that result in the stackoverflow answer. Hope it'll help !

Thank you so much! That solves it. Upvoted on stackoverflow.

Wintermute79 avatar Apr 27 '22 14:04 Wintermute79

+1 for this

tuyuribr avatar Sep 05 '22 22:09 tuyuribr

+1 for this

namiwa avatar Feb 06 '23 16:02 namiwa

+1 for this

StefanKX avatar Mar 21 '23 06:03 StefanKX

+1 for this

xitice avatar Jun 28 '23 07:06 xitice

+1

vildantursic avatar Sep 28 '23 11:09 vildantursic

+1

amartin-wbd avatar Dec 12 '23 21:12 amartin-wbd

+1000 For this. The library has this weird behavior for some years. When it has data points misaligned by X then not all points comes to the tooltip.formatter. Doc searching doesn't help. No success.

My current case for example: software getting multiple sensors data at different time interval. It leads to having misaligned series data x-values. Maybe this solution could be help, but business has requirement to display big data. So iteration over big data list can suffer performance a lot. Maybe anyone solve this in any other way? I'm drained by constant experimenting on this.

mistical2008 avatar Mar 11 '24 18:03 mistical2008

+1

zebleck avatar Mar 13 '24 12:03 zebleck

Hey @Ovilia any news on this?

vildantursic avatar Mar 21 '24 09:03 vildantursic

After spending some time porting my solution to Echarts, I'll say that this comes as a very big surprise. I had assumed tooltips would display the interpolated value at a given point in time, or provide similar configuration to achieve it.

I don't have the ability to control the sampling of some of my data, several temperature time series, and that's leading to a very negative experience regarding tooltips.

RyKilleen avatar Apr 05 '24 16:04 RyKilleen