how to pass unit to eCharts tooltip formatter

Viewed 797

I am trying to display the unit for a series using eCharts however I am unsure how eCharts actually gets the data for the formatter params. I have a plot config object like this:

plotConfig = {
  tooltip: {
    trigger: 'axis',
    formatter: timeseriesTooltip,
  }
}

then the formatter function is like this:

const timeseriesTooltip = (series) => {
  let tooltip = '';
  const [firstSeries] = series;
  const title = moment(firstSeries.axisValue).format('HH:mm:ss - DD-MM-YYYY');
  tooltip += `<div>${title}</div>`;

  series.forEach((s) => {
    tooltip += `<div>${s.marker} ${s.seriesName}: ${s.value[1] ? s.value[1].toFixed(2) : ''}</div>`;
  });

  return tooltip;
};

I want to dynamically add a unit after the series value but I am not sure how to pass it in or what field to set on my series object so eCharts will pick it up.

0 Answers
Related