소스 검색

chore: 尝试雷达图组件开发

tnt group 3 년 전
부모
커밋
7cac99dd80

+ 37 - 0
src/packages/components/Charts/Mores/Radar/config.ts

@@ -0,0 +1,37 @@
+import { echartOptionProfixHandle, publicConfig } from '@/packages/public'
+import { RadarConfig } from './index'
+import { CreateComponentType } from '@/packages/index.d'
+import cloneDeep from 'lodash/cloneDeep'
+import dataJson from './data.json'
+
+export const includes = ['legend']
+
+export const option = {
+  tooltip: {
+    show: true
+  },
+  legend: {
+    show: true
+  },
+  radar: {
+    indicator: dataJson.radarIndicator
+  },
+  dataset: { ...dataJson },
+  series: [
+    {
+      type: 'radar',
+      barWidth: null,
+      itemStyle: {
+        color: null,
+        borderRadius: 0
+      }
+    }
+  ]
+}
+
+export default class Config extends publicConfig implements CreateComponentType {
+  public key = RadarConfig.key
+  public chartConfig = cloneDeep(RadarConfig)
+  // 图表配置项
+  public option = echartOptionProfixHandle(option, includes)
+}

+ 21 - 0
src/packages/components/Charts/Mores/Radar/data.json

@@ -0,0 +1,21 @@
+{
+  "legendData": ["Allocated Budget", "Actual Spending"],
+  "radarIndicator": [
+    { "name": "Sales", "max": 6500 },
+    { "name": "Administration", "max": 16000 },
+    { "name": "Information Technology", "max": 30000 },
+    { "name": "Customer Support", "max": 38000 },
+    { "name": "Development", "max": 52000 },
+    { "name": "Marketing", "max": 25000 }
+  ],
+  "seriesData": [
+    {
+      "value": [4200, 3000, 20000, 35000, 50000, 18000],
+      "name": "Allocated Budget"
+    },
+    {
+      "value": [5000, 14000, 28000, 26000, 42000, 21000],
+      "name": "Actual Spending"
+    }
+  ]
+}

+ 2 - 1
src/packages/components/Charts/Mores/Radar/index.ts

@@ -1,5 +1,5 @@
 import image from '@/assets/images/chart/charts/radar.png'
-import { ConfigType, PackagesCategoryEnum } from '@/packages/index.d'
+import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
 import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
 
 export const RadarConfig: ConfigType = {
@@ -10,5 +10,6 @@ export const RadarConfig: ConfigType = {
   category: ChatCategoryEnum.MORE,
   categoryName: ChatCategoryEnumName.MORE,
   package: PackagesCategoryEnum.CHARTS,
+  chartFrame: ChartFrameEnum.ECHARTS,
   image
 }

+ 34 - 6
src/packages/components/Charts/Mores/Radar/index.vue

@@ -1,13 +1,41 @@
 <template>
-  <div>
-    水波
-  </div>
+  <v-chart ref="vChartRef" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart>
 </template>
 
 <script setup lang="ts">
+import { computed, PropType } from 'vue'
+import VChart from 'vue-echarts'
+import { use } from 'echarts/core'
+import { CanvasRenderer } from 'echarts/renderers'
+import { RadarChart } from 'echarts/charts'
+import { includes } from './config'
+import { mergeTheme } from '@/packages/public/chart'
+import { useChartDataFetch } from '@/hooks'
+import { CreateComponentType } from '@/packages/index.d'
+import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
+import { isPreview } from '@/utils'
+import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
 
-</script>
+const props = defineProps({
+  themeSetting: {
+    type: Object,
+    required: true
+  },
+  themeColor: {
+    type: Object,
+    required: true
+  },
+  chartConfig: {
+    type: Object as PropType<CreateComponentType>,
+    required: true
+  }
+})
+
+use([DatasetComponent, CanvasRenderer, RadarChart, GridComponent, TooltipComponent, LegendComponent])
 
-<style lang="scss" scoped>
+const option = computed(() => {
+  return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
+})
 
-</style>
+const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
+</script>