diff --git a/src/assets/icons/circle.svg b/src/assets/icons/circle.svg new file mode 100644 index 00000000..f2584fff --- /dev/null +++ b/src/assets/icons/circle.svg @@ -0,0 +1,15 @@ + + \ No newline at end of file diff --git a/src/hooks/useLegendProcessor.ts b/src/hooks/useLegendProcessor.ts index 84155782..c9d60323 100644 --- a/src/hooks/useLegendProcessor.ts +++ b/src/hooks/useLegendProcessor.ts @@ -35,7 +35,9 @@ export default function useLegendProcess(legend?: LegendOptions) { } function aggregations(data: { [key: string]: number[] }) { const source: { [key: string]: unknown }[] = []; - const keys = Object.keys(data); + const keys = Object.keys(data || {}).filter( + (i: any) => Array.isArray(data[i]) && data[i].length + ); const headers = []; for (const [key, value] of keys.entries()) { @@ -81,5 +83,37 @@ export default function useLegendProcess(legend?: LegendOptions) { return { source, headers }; } - return { showEchartsLegend, isRight, aggregations }; + function chartColors(keys: string[]) { + let color: string[] = []; + switch (keys.length) { + case 2: + color = ["#FF6A84", "#a0b1e6"]; + break; + case 1: + color = ["#3f96e3"]; + break; + default: + color = [ + "#30A4EB", + "#45BFC0", + "#FFCC55", + "#FF6A84", + "#a0a7e6", + "#c23531", + "#2f4554", + "#61a0a8", + "#d48265", + "#91c7ae", + "#749f83", + "#ca8622", + "#bda29a", + "#6e7074", + "#546570", + "#c4ccd3", + ]; + break; + } + return color; + } + return { showEchartsLegend, isRight, aggregations, chartColors }; } diff --git a/src/views/dashboard/graphs/Bar.vue b/src/views/dashboard/graphs/Bar.vue index a3627e80..1c151c06 100644 --- a/src/views/dashboard/graphs/Bar.vue +++ b/src/views/dashboard/graphs/Bar.vue @@ -49,7 +49,9 @@ const props = defineProps({ default: () => ({}), }, }); -const { showEchartsLegend, isRight } = useLegendProcess(props.config.legend); +const { showEchartsLegend, isRight, chartColors } = useLegendProcess( + props.config.legend +); const option = computed(() => getOption()); function getOption() { @@ -79,35 +81,7 @@ function getOption() { }, }; }); - let color: string[] = []; - switch (keys.length) { - case 2: - color = ["#FF6A84", "#a0b1e6"]; - break; - case 1: - color = ["#3f96e3"]; - break; - default: - color = [ - "#30A4EB", - "#45BFC0", - "#FFCC55", - "#FF6A84", - "#a0a7e6", - "#c23531", - "#2f4554", - "#61a0a8", - "#d48265", - "#91c7ae", - "#749f83", - "#ca8622", - "#bda29a", - "#6e7074", - "#546570", - "#c4ccd3", - ]; - break; - } + const color: string[] = chartColors(keys); return { color, tooltip: { diff --git a/src/views/dashboard/graphs/Line.vue b/src/views/dashboard/graphs/Line.vue index bbabdf50..17777181 100644 --- a/src/views/dashboard/graphs/Line.vue +++ b/src/views/dashboard/graphs/Line.vue @@ -64,7 +64,9 @@ const props = defineProps({ }), }, }); -const { showEchartsLegend, isRight } = useLegendProcess(props.config.legend); +const { showEchartsLegend, isRight, chartColors } = useLegendProcess( + props.config.legend +); const option = computed(() => getOption()); function getOption() { const keys = Object.keys(props.data || {}).filter( @@ -95,35 +97,7 @@ function getOption() { } return serie; }); - let color: string[] = []; - switch (keys.length) { - case 2: - color = ["#FF6A84", "#a0b1e6"]; - break; - case 1: - color = ["#3f96e3"]; - break; - default: - color = [ - "#30A4EB", - "#45BFC0", - "#FFCC55", - "#FF6A84", - "#a0a7e6", - "#c23531", - "#2f4554", - "#61a0a8", - "#d48265", - "#91c7ae", - "#749f83", - "#ca8622", - "#bda29a", - "#6e7074", - "#546570", - "#c4ccd3", - ]; - break; - } + const color: string[] = chartColors(keys); const tooltip = { trigger: "none", axisPointer: { diff --git a/src/views/dashboard/graphs/components/Legend.vue b/src/views/dashboard/graphs/components/Legend.vue index 35073479..e66c6fff 100644 --- a/src/views/dashboard/graphs/components/Legend.vue +++ b/src/views/dashboard/graphs/components/Legend.vue @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. -->