diff --git a/src/hooks/useSnapshot.ts b/src/hooks/useSnapshot.ts index 2788fd44..59b31cb8 100644 --- a/src/hooks/useSnapshot.ts +++ b/src/hooks/useSnapshot.ts @@ -17,7 +17,7 @@ import type { MetricsResults } from "@/types/dashboard"; import { TestJson } from "./data"; -export function useSnapshot(params: { name: string; results: MetricsResults[] }[]) { +export function useSnapshot(p: { name: string; results: MetricsResults[] }[]) { const { metrics } = TestJson.snapshot as any; function processResults() { const sources = metrics.map((metric: { name: string; results: MetricsResults[] }) => { @@ -48,8 +48,10 @@ export function useSnapshot(params: { name: string; results: MetricsResults[] }[ if (!item.metric.labels.length) { metricsMap[metric.name] = arr; } else { - const label = item.metric.labels[0]; - metricsMap[`${label.key}=${label.value}`] = arr; + const name = item.metric.labels + .map((label: { key: string; value: string }) => `${label.key}=${label.value}`) + .join(","); + metricsMap[name] = arr; } } } diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 5ddb9130..d021e48d 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -112,6 +112,7 @@ export interface LineConfig extends AreaConfig { smallTips?: boolean; showlabels?: boolean; noTooltips?: boolean; + showLegend?: boolean; } export interface AreaConfig { diff --git a/src/views/alarm/Content.vue b/src/views/alarm/Content.vue index 6201fa1f..8d9773d0 100644 --- a/src/views/alarm/Content.vue +++ b/src/views/alarm/Content.vue @@ -43,6 +43,7 @@ limitations under the License. --> smallTips: false, showlabels: false, noTooltips: true, + showLegend: false, }" /> @@ -167,8 +168,10 @@ limitations under the License. --> function handleMetrics(snapshot: { metrics: { name: string; results: MetricsResults[] }[] }) { const { getMetricsMap } = useSnapshot(snapshot.metrics); + const metrics = getMetricsMap(); + const keys = Object.keys(metrics); - return getMetricsMap(); + return { [keys[0]]: metrics[keys[0]] }; } diff --git a/src/views/dashboard/graphs/Line.vue b/src/views/dashboard/graphs/Line.vue index d6a199c9..d91b31c2 100644 --- a/src/views/dashboard/graphs/Line.vue +++ b/src/views/dashboard/graphs/Line.vue @@ -61,6 +61,7 @@ limitations under the License. --> smallTips: false, showlabels: true, noTooltips: false, + showLegend: true, }), }, }); @@ -129,7 +130,7 @@ limitations under the License. --> tooltip: props.config.smallTips ? tips : tooltip, legend: { type: "scroll", - show: showEchartsLegend(keys), + show: props.config.showLegend ? showEchartsLegend(keys) : false, icon: "circle", top: 0, left: 0,