apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser

Home Page:https://echarts.apache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Allow callback functions to access the scale extents

mlvn23 opened this issue · comments

What problem does this feature solve?

I'm working on an OHLC/Candlestick chart, and it looks like I need to use the category axis to avoid the gaps. I wanted to implement a custom xAxis tick and labeler so that the ticks are demarcated, not based on random dates/times produced by the no label overlap algo, but on major logical points like start of the month, start of the year, start of the hour, etc like these:

image
image

For me to implement a sophisticated labeler / ticker function, I need to know what is the current data that's show in the chart. There's no API for this as far as I know, and I had to resort to a hack like this:

let [startIdx, endIdx] = myChart._chartsViews[0].__model.coordinateSystem._axes.x.scale._extent;

I did try the datazoomEvent, but the labeler / ticker function fires first, so I can't use it.

What does the proposed API look like?

I'm proposing to add an extra object parameter in the callback function of axisTick.interval and axisLabel.interval that includes information that helps in creating sophisticated ticker / labelers:

(index:number, value: string, params: Object) => boolean

Same goes for axisLabel.formatter:

(value: string, index: number, params: Object) => string

The params Object will include information that would let us derive which span of data is currently shown.

See if this PR helps: #19919