[Feature] Time axis interval
- Dominant language
- TypeScript
- Stars
- 67.3k
- Forks
- 19.8k
- Avg merge
- 11d 14h
- Merged PRs (30d)
- 8
Description
### What problem does this feature solve?
Since [v5](https://github.com/apache/echarts/pull/12859), the `interval` option of time axes is no long valid because the span of each two ticks are not always the same (e.g., Feburary has 28/29 days while March has 31 days). But it's a common requirement to set the interval level (or the minimium interval level) to be yearly/monthly/dayly/... and it can hardly be done with the current API.
### What does the proposed API look like?
I'd suggest we support `interval`, `minInterval`, and `maxInterval` in the type of [`TimeUnit`](https://github.com/apache/echarts/blob/6ee5f7076d84b72dc65b4c53e92e5003b8624b2f/src/util/time.ts#L58). If the developer want to set the interval to be 4 days, `'4 days'` or `'4 day'` is also valid.
So, valid examples of `interval`s include: `'year'`, `'quarter'`, `'4 days'`, `'4 day'`, `'30 minutes'`, and etc.
> #17044 is trying to provide a number typed `interval` but this cannot solve the problem of each month having different days. Using the interval of `1000 * 3600 * 24 * 30` is not accurate and logically not correct. Similar for the leap year problem.
For example, to display use ticks by month:
```ts
xAxis: {
type: 'time',
interval: 'month',
axisLabel: { // optional
showMinLabel: true,
formatter: {
year: '{yyyy}',
month: '{MMM}',
day: '{yyyy} {MMM}'' // hack for the first day
}
}
}
```
The ticks will be at the first date of each month (excluding the first one because it's displaying only because `showMinLabel: true`):
```
|_____________|__________________________|__________________________|__ ...
2019 Dec 2020 Feb March
```
`minInterval` and `maxInterval` works similarly.
Note that if `interval` is set to be like `'4 days'`, the first day of each month may not be on ticks any more:
```
|________|________|________|________ ...
6/21 6/25 6/29 7/3
```
In this case, `7/1` is not included in the ticks. #16335
## Related issues
- #16927
- #17519
- #16142
- #15266
- #14305
- #14298
Contributor guide
Assessment
This issue has not been assessed yet.