echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Feature] Want to access tickInterval in the y-axis formatter

Open cndonovan opened this issue 1 year ago • 2 comments

What problem does this feature solve?

When formatting the values on the y-axis, I want to be able to take into account the y-axis minimum and y-axis maximum.

Why? When I am showing values on the y-axis, I want to know the precision needed to distinguish between each value, and format each value with exactly that much precision. For example, if the y-axis values are [1, 0.98, 0.96, 0.94, 0.92, 0.9], then I want to format as [1.00, 0.98, 0.96, 0.94, 0.92, .090].

What does the proposed API look like?

formatter: (value, index, range) => {
  // Use range.mix and range.max to decide how to format value
}

Edit

I'd actually benefit more from knowing the tick interval (i.e. the difference between consecutive tick lines). I'd prefer:

formatter: (value, index, tickInterval) => {
   // Use tickInterval to decide how to format value
}

cndonovan avatar Oct 16 '24 22:10 cndonovan

As a possible workaround you can take look at this stackoverflow post.

MatthiasMert avatar Oct 17 '24 05:10 MatthiasMert

I edited my original message, but I'll comment here too:

Edit

I'd actually benefit more from knowing the tick interval (i.e. the difference between consecutive tick lines).

formatter: (value, index, tickInterval) => {
   // Use tickInterval to decide how to format value
}

Like I said, my goal is: if the y-axis values are [1, 0.98, 0.96, 0.94, 0.92, 0.9], then I want to format as [1.00, 0.98, 0.96, 0.94, 0.92, 0.90].

If I know that the tickInterval is .02, then I can choose to format with two decimal places.

cndonovan avatar Oct 17 '24 20:10 cndonovan