leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.77k stars 386 forks source link

Attach metadata to data point #1010

Open yumochi opened 1 day ago

yumochi commented 1 day ago

Hi,

Bit new to uPlot. I am using a react version of uPlot, and I am wondering what is the best way to display additional metadata to my data point on hover with cursor?

To be more specific, we already display a value for every series on hover over the data point, but can we render additional meta data for that point as well?

leeoniya commented 1 day ago

sure, you can use series.values option to return an object of properties to display in a table-style legend.

examples:

https://leeoniya.github.io/uPlot/demos/scatter.html https://github.com/leeoniya/uPlot/blob/f98d1d34d92a128f18fbaac9293910eed85ea19c/demos/scatter.html#L416-L435

https://leeoniya.github.io/uPlot/demos/time-periods.html https://github.com/leeoniya/uPlot/blob/f98d1d34d92a128f18fbaac9293910eed85ea19c/demos/time-periods.html#L128-L139

you can hold these values as additional data arrays that are not defined in the options.series array, and access them from there.