I am hoping to use a different format specifically for the top axis label on my y-axis. For example, if I have a percentage value axis, I would like to see the % symbol only on the top axis label, while the rest of the labels beneath it remain formatted as numbers without a symbol.
So far, I've been using the formatter option and have created a function that receives value and index per the ECharts docs. The example link below does what I need it to do, but does it for the bottom of the axis rather than the top. I need a way to use this same logic, but select the maximum index on the axis.
Link to example in docs:
https://echarts.apache.org/en/option.html#yAxis.axisLabel.formatter
Code from example in docs:
The if (index === 0) is the logic I'm referring to
// Use callback function; function parameters are axis index
formatter: function (value, index) {
// Formatted to be month/day; display year only in the first label
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
}
Here's what I've tried:
- I attempted to use the
indexargument to figure out the max index # in my dataset, but couldn't figure out how to do that given that the function is called once per value and includes only the data for that value. - I tried passing
paramsto the function since that's howformatterworks in theseriesconfig, but it looks like that's not possible in theaxisconfig - One (unattractive) alternative is to use the y-axis
axisNameto display any symbols I want to have appended to the top label, and manually position it usingpadding. This probably wouldn't work because I'll also need to use theaxisNameseparately from time to time.
A Possible Hint
This might not be possible yet, but at least behind the scenes I know ECharts is able to select the top label through the showMaxLabel option in axisLabel.
Is there a way to check if a label is the maximum label in the formatter function for an axis?