|
@@ -666,16 +666,32 @@ const convertTo24Hour = (timeStr: string) => {
|
|
|
let [hours, period] = timeStr.split(" ");
|
|
|
return (period === "pm" ? (+hours % 12) + 12 : +hours % 12).toString();
|
|
|
};
|
|
|
+/**
|
|
|
+ * 将 24 小时制数字转换为 12 小时制格式
|
|
|
+ * @param hour 24 小时制的小时数
|
|
|
+ * @returns {string} 转换后的 12 小时制格式
|
|
|
+ */
|
|
|
+const convertTo12HourFormat = (hour: number): string => {
|
|
|
+ if (hour === 0 || hour === 24) {
|
|
|
+ return '12a';
|
|
|
+ } else if (hour === 12) {
|
|
|
+ return '12p';
|
|
|
+ } else if (hour > 12) {
|
|
|
+ return `${hour - 12}p`;
|
|
|
+ } else {
|
|
|
+ return `${hour}a`;
|
|
|
+ }
|
|
|
+}
|
|
|
// { x: 0, y: 0, value: 5, type: "p" }
|
|
|
const transformData= (data:DataPoint[]) => {
|
|
|
const weekDayMap = {
|
|
|
- "星期一": 1,
|
|
|
- "星期二": 2,
|
|
|
- "星期三": 3,
|
|
|
- "星期四": 4,
|
|
|
- "星期五": 5,
|
|
|
- "星期六": 6,
|
|
|
- "星期日": 7
|
|
|
+ "星期一": '周一',
|
|
|
+ "星期二": '周二',
|
|
|
+ "星期三": '周三',
|
|
|
+ "星期四": '周四',
|
|
|
+ "星期五": '周五',
|
|
|
+ "星期六": '周六',
|
|
|
+ "星期日": '周日'
|
|
|
};
|
|
|
return data.map(item => {
|
|
|
const { x, y, type, ...rest } = item;
|
|
@@ -690,7 +706,7 @@ const transformData= (data:DataPoint[]) => {
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
- x: x,
|
|
|
+ x: convertTo12HourFormat(x),
|
|
|
y: weekDayMap[y],
|
|
|
value:valueArray,
|
|
|
type: `${type}`
|