echarts

Multiple tooltip valueFormatters


Is it possible to configure the tooltip option to accept multiple valueFormatter for each series? Let's say I have a series containing temperature data and another series containing heart rate. I would like to format these with different units (°C and Bpm respectively) and number of decimals.

I am aware that I can use the formatter option to achieve this task but that gets rid of the default tooltip styling which I would like to keep. Does anyone know of a way?


Solution

  • You can configure the tooltip for each series individually under series.tooltip.

    Example:

    series: [
        {
            ...,
            tooltip: {
                valueFormatter: value => value + ' °C'
            }
        },
        {
            ...,
            tooltip: {
                valueFormatter: value => value + ' Bpm'
            }
        },
    ]