import moment and declare primevue option

This commit is contained in:
Cindy Chang
2024-06-17 21:51:19 +08:00
parent 9f121eb5d4
commit 541c0080aa

View File

@@ -3,15 +3,68 @@
</template> </template>
<script> <script>
import Moment from 'moment';
import { computed, ref, onMounted } from 'vue'; import { computed, ref, onMounted } from 'vue';
import { import {
setTimeStringFormatBaseOnTimeDifference, setTimeStringFormatBaseOnTimeDifference,
mapTimestampToAxisTicksByFormat, mapTimestampToAxisTicksByFormat,
} from '@/module/timeLabel.js'; } from '@/module/timeLabel.js';
import {
knownScaleLineChartOptions,
} from "@/constants/constants.js";
const knownScaleLineChartOptions = {
x: {
type: 'time',
title: {
display: true,
color: '#334155',
font: {
size: 12,
lineHeight: 2
}
},
time: {
displayFormats: {
second: 'h:mm:ss', // ex: 1:11:11
minute: 'M/d h:mm', // ex: 1/1 1:11
hour: 'M/d h:mm', // ex: 1/1 1:11
day: 'M/d h', // ex: 1/1 1
month: 'y/M/d', // ex: 1911/1/1
},
},
ticks: {
display: true,
maxRotation: 0, // 不旋轉 lable 0~50
color: '#64748b',
source: 'labels', // 依比例彈性顯示 label 數量
},
border: {
color: '#64748b',
},
grid: {
tickLength: 0, // 網格是否超過邊線
}
},
y: {
beginAtZero: true, // scale 包含 0
title: {
display: true,
color: '#334155',
font: {
size: 12,
lineHeight: 2
},
},
ticks:{
color: '#64748b',
padding: 8,
},
grid: {
color: '#64748b',
},
border: {
display: false, // 隱藏左側多出來的線
},
},
};
// 試著把 chart 獨立成一個 vue component // 試著把 chart 獨立成一個 vue component
// 企圖防止 PrimeVue 誤用其他圖表 option 值的 bug // 企圖防止 PrimeVue 誤用其他圖表 option 值的 bug
@@ -125,7 +178,7 @@ export default {
let primeVueSetData = {}; let primeVueSetData = {};
let primeVueSetOption = {}; let primeVueSetOption = {};
const getMoment = (time)=> { const getMoment = (time)=> {
return this.$moment(time).format('YYYY/M/D hh:mm:ss') return Moment(time).format('YYYY/M/D hh:mm:ss')
}; };
// 考慮 chartData.data 的dimension // 考慮 chartData.data 的dimension