update charts

This commit is contained in:
Fine 2025-01-06 17:46:57 +08:00
parent 31a40b1342
commit 926678e311
3 changed files with 70 additions and 45 deletions

View File

@ -19,7 +19,7 @@ export function useSnapshot(metrics: { name: string; results: any[] }[]) {
function processResults() { function processResults() {
const sources = metrics.map((metric: { name: string; results: any[] }) => { const sources = metrics.map((metric: { name: string; results: any[] }) => {
const values = metric.results.map((r: { values: { value: string }[] }) => const values = metric.results.map((r: { values: { value: string }[] }) =>
r.values.map((v: { value: string }) => v.value), r.values.map((v: { value: string }) => Number(v.value)),
); );
return { [metric.name]: values[0] }; return { [metric.name]: values[0] };

View File

@ -37,11 +37,17 @@ limitations under the License. -->
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const option = computed(() => getOption()); const option = computed(() => getOption());
function getOption() { function getOption() {
const keys = Object.keys(props.data || {}).filter((i: any) => Array.isArray(props.data[i]) && props.data[i].length); const keys = Object.keys(props.data || {}).filter(
const series = keys.map((i: any) => { (i: string) => Array.isArray(props.data[i]) && props.data[i].length,
const serie: any = { );
data: props.data[i].map((item: any, itemIndex: number) => [props.intervalTime[itemIndex], item]), const series = [];
name: i, const grid = [];
const xAxis = [];
const yAxis = [];
for (const key of keys) {
series.push({
data: props.data[key].map((item: any, itemIndex: number) => [props.intervalTime[itemIndex], item]),
name: key,
type: "line", type: "line",
symbol: "circle", symbol: "circle",
symbolSize: 4, symbolSize: 4,
@ -49,9 +55,38 @@ limitations under the License. -->
width: 2, width: 2,
type: "solid", type: "solid",
}, },
}; });
return serie; grid.push({
}); top: 35,
left: 0,
right: 10,
bottom: 5,
containLabel: true,
});
xAxis.push({
type: "category",
show: true,
axisTick: {
lineStyle: { color: "#c1c5ca41" },
alignWithLabel: true,
},
splitLine: { show: false },
axisLine: { lineStyle: { color: "rgba(0,0,0,0)" } },
axisLabel: { color: "#9da5b2", fontSize: "11" },
});
yAxis.push({
show: true,
type: "value",
axisLine: { show: false },
axisTick: { show: false },
splitLine: { lineStyle: { color: "#c1c5ca41", type: "dashed" } },
axisLabel: {
color: "#9da5b2",
fontSize: "11",
show: true,
},
});
}
const { chartColors } = useLegendProcess(); const { chartColors } = useLegendProcess();
const color: string[] = chartColors(); const color: string[] = chartColors();
const tooltip = { const tooltip = {
@ -65,14 +100,19 @@ limitations under the License. -->
enterable: true, enterable: true,
confine: true, confine: true,
extraCssText: "max-height:85%; overflow: auto;", extraCssText: "max-height:85%; overflow: auto;",
axisPointer: {
animation: false,
},
}; };
return { return {
color, color,
tooltip, tooltip,
axisPointer: {
link: { xAxisIndex: "all" },
},
legend: { legend: {
type: "scroll", type: "scroll",
show: true,
icon: "circle", icon: "circle",
top: 0, top: 0,
left: 0, left: 0,
@ -81,36 +121,9 @@ limitations under the License. -->
color: appStore.theme === Themes.Dark ? "#fff" : "#333", color: appStore.theme === Themes.Dark ? "#fff" : "#333",
}, },
}, },
grid: { grid,
top: 35, xAxis,
left: 0, yAxis,
right: 10,
bottom: 5,
containLabel: true,
},
xAxis: {
type: "category",
show: true,
axisTick: {
lineStyle: { color: "#c1c5ca41" },
alignWithLabel: true,
},
splitLine: { show: false },
axisLine: { lineStyle: { color: "rgba(0,0,0,0)" } },
axisLabel: { color: "#9da5b2", fontSize: "11" },
},
yAxis: {
show: true,
type: "value",
axisLine: { show: false },
axisTick: { show: false },
splitLine: { lineStyle: { color: "#c1c5ca41", type: "dashed" } },
axisLabel: {
color: "#9da5b2",
fontSize: "11",
show: true,
},
},
series, series,
}; };
} }

View File

@ -13,17 +13,29 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div class="snapshot flex-v"> Line Charts </div> <div class="snapshot flex-v">
<LineChart :intervalTime="appStore.intervalTime" :data="result" />
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue";
import { useSnapshot } from "@/hooks/useSnapshot"; import { useSnapshot } from "@/hooks/useSnapshot";
import { useAppStoreWithOut } from "@/store/modules/app";
import LineChart from "./Line.vue";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
snapshot: { type: Object, default: () => {} }, snapshot: { type: Object, default: () => {} },
}); });
const appStore = useAppStoreWithOut();
const { processResults } = useSnapshot(props.snapshot.metrics); const result = computed(() => {
const data = processResults(); const { processResults } = useSnapshot(props.snapshot.metrics);
return processResults().reduce((acc, obj) => ({ ...acc, ...obj }), {});
});
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped>
.snapshot {
width: 800px;
height: 600px;
}
</style>