yl-endress commented on issue #20027:
URL: https://github.com/apache/echarts/issues/20027#issuecomment-2165555578
For everyone else who is having issues to format the x-axis in a specific
timezone, I found a solution as a workaround:
Use your own formatter function by using the way how it's written in the
documentation.
```
...
axisLabel: {
formatter: (value) => {
return this.getFormattedUnitFromValue(value);
}
}
...
```
Finally extract the functionality of
https://github.com/apache/echarts/blob/master/src/util/time.ts#L223C3-L223C31
to your needs, like the following:
```
private getFormattedUnitFromValue(
value: number | string | Date,
): string {
// The following code is kind of a copy to distinquish which format
should be used
const isUTC: boolean = this.useUtc;
const date: Date = new Date(value);
const M: number = (isUTC ? date.getUTCMonth() : date.getMonth()) + 1;
const d: number = isUTC ? date.getUTCDate() : date.getDate();
const h: number = isUTC ? date.getUTCHours() : date.getHours();
const m: number = isUTC ? date.getUTCMinutes() : date.getMinutes();
const s: number = isUTC ? date.getUTCSeconds() : date.getSeconds();
const S: number = isUTC ? date.getUTCMilliseconds() :
date.getMilliseconds();
const isSecond: boolean = S === 0;
const isMinute: boolean = isSecond && s === 0;
const isHour: boolean = isMinute && m === 0;
const isDay: boolean = isHour && h === 0;
const isMonth: boolean = isDay && d === 1;
const isYear: boolean = isMonth && M === 1;
// Here you can put your own format logic
const is24hFormat: boolean = !this.myTimeFormat.includes("am");
let format: string;
if (isYear) {
format = "yyyy";
} else if (isMonth) {
format = "MMM";
} else if (isDay) {
format = "d. MMM";
} else if (isHour) {
format = is24hFormat ? "hh:mm a\nd. MMM" : "HH:mm\nd. MMM";
} else if (isMinute) {
format = is24hFormat ? "hh:mm:ss a\nd. MMM" : "HH:mm\nd. MMM";
} else if (isSecond) {
format = is24hFormat ? "hh:mm:ss a\nd. MMM" : "HH:mm:ss\nd. MMM";
} else {
format = is24hFormat ? "hh:mm:ss SSS a\nd. MMM" : "HH:mm:ss SSS\nd.
MMM";
}
// Finally, you can use your logic to handle specific timezones
return this.dateTimePipe.transform(date, format); // Angular example
with a custom datePipe
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]