Version
5.3.3
Link to Minimal Reproduction
https://codesandbox.io/s/echarts-playground-forked-ulq2zv
Steps to Reproduce
In the codesandbox is the code. You can see there are 2 charts. All the same. The only difference is:
First chart has in xAxis
type of time
☝️ with time
we lost sorting of data
Second chart has in yAxis
type of category
☝️ with category
we lost axis formatting as time and time scale nice spacing (Look that nice Dec
month in first chart).
If you check the small dataset you'll see it's ordered in ASC
order.
const dataset = [
["date", "amount"],
["2022-11-01", "1"],
["2022-11-02", "2"],
["2022-11-05", "3"],
["2022-11-13", "4"],
["2022-11-20", "5"],
["2022-12-07", "6"],
["2022-12-04", "7"],
["2022-11-10", "8"],
["2022-12-15", "9"],
["2022-12-24", "10"]
];
Current Behavior
First chart where xAxis
is of type time
the order of the dataset is not respected.
Expected Behavior
I'm not sure if this is possible or even expected but I would love to be able to have the nice work Echarts does with time
scale axis formatting and deciding the right amount of ticks based on volume but respecting the order of the dataset.
Environment
- OS:
- Browser:
- Framework:
Any additional comments?
What I would want is to have a time series axis with formatting and tick spacing but the order would be mark by dataset.
6条答案
按热度按时间km0tfn4u1#
This is by design.
When xAxis is type='time', X axis values are sorted automatically b/c they need to be in (time) order.
Result: "2022-12-07" shows after "2022-12-04" correctly.
When xAxis is type='category', order does not matter and X axis values appear as they are in the dataset.
Result: "2022-12-07" shows before "2022-12-04", which is incorrect.
Y values ('amount') show always in their original dataset sequence. That's why after sorting the dataset with
source: dataset.sort()
, we get a different polyline, even though the individual values remain the same.Demo Code
bbmckpt72#
This is by design.
That was my suspicion.
My question is if it's possible to get the benefits of
time
scale cascading automatic formatted time based without enforced time sorting on X axesfv2wmkja3#
But "Cascading Templates: to adopt different formatters for different time granularity" - is just 'makeup' (formatting) of the values, it does not affect the axis-values order.
If you want "without enforced time sorting on X axes", the answer is already in your example - use xAxis type='category'.
Could you provide a desired output chart to clarify your goal ?
jfgube3f4#
So I guess my question is how I can use cascading templates on a
category
type axis?tuwxkamq5#
In fact Cascading Templates are for time type axis only.
For category type axis one could use Callback Functions formatting.
Demo Code
wztqucjr6#
I know I can use a callback function. I was asking for a way of using cascading templates without reimplementing it myself : ) . Thanks anyway