Commit 89225bce1c42020af66bf64484943e83b91161e4
1 parent
837f7254
feat(src/packages): 图表双折线支持导入多个数据源
Showing
3 changed files
with
77 additions
and
72 deletions
@@ -7,11 +7,38 @@ import cloneDeep from 'lodash/cloneDeep' | @@ -7,11 +7,38 @@ import cloneDeep from 'lodash/cloneDeep' | ||
7 | import dataJson from './data.json' | 7 | import dataJson from './data.json' |
8 | 8 | ||
9 | export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] | 9 | export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] |
10 | - | 10 | +export const seriesItem = { |
11 | + type: 'line', | ||
12 | + smooth: false, | ||
13 | + symbolSize: 5, //设定实心点的大小 | ||
14 | + label: { | ||
15 | + show: true, | ||
16 | + position: 'top', | ||
17 | + color: '#fff', | ||
18 | + fontSize: 12 | ||
19 | + }, | ||
20 | + lineStyle: { | ||
21 | + width: 3, | ||
22 | + type: 'solid' | ||
23 | + }, | ||
24 | + areaStyle: { | ||
25 | + opacity: 0.8, | ||
26 | + color: new graphic.LinearGradient(0, 0, 0, 1, [ | ||
27 | + { | ||
28 | + offset: 0, | ||
29 | + color: chartColorsSearch[defaultTheme][3] | ||
30 | + }, | ||
31 | + { | ||
32 | + offset: 1, | ||
33 | + color: 'rgba(0,0,0,0)' | ||
34 | + } | ||
35 | + ]) | ||
36 | + } | ||
37 | +} | ||
11 | // 其它配置项比如新增(动画) | 38 | // 其它配置项比如新增(动画) |
12 | const otherConfig = { | 39 | const otherConfig = { |
13 | // 轮播动画 | 40 | // 轮播动画 |
14 | - isCarousel: false, | 41 | + isCarousel: false |
15 | } | 42 | } |
16 | const option = { | 43 | const option = { |
17 | ...otherConfig, | 44 | ...otherConfig, |
@@ -31,63 +58,7 @@ const option = { | @@ -31,63 +58,7 @@ const option = { | ||
31 | type: 'value' | 58 | type: 'value' |
32 | }, | 59 | }, |
33 | dataset: { ...dataJson }, | 60 | dataset: { ...dataJson }, |
34 | - series: [ | ||
35 | - { | ||
36 | - type: 'line', | ||
37 | - smooth: false, | ||
38 | - symbolSize: 5, //设定实心点的大小 | ||
39 | - label: { | ||
40 | - show: true, | ||
41 | - position: 'top', | ||
42 | - color: '#fff', | ||
43 | - fontSize: 12 | ||
44 | - }, | ||
45 | - lineStyle: { | ||
46 | - width: 3, | ||
47 | - type: 'solid' | ||
48 | - }, | ||
49 | - areaStyle: { | ||
50 | - opacity: 0.8, | ||
51 | - color: new graphic.LinearGradient(0, 0, 0, 1, [ | ||
52 | - { | ||
53 | - offset: 0, | ||
54 | - color: chartColorsSearch[defaultTheme][3] | ||
55 | - }, | ||
56 | - { | ||
57 | - offset: 1, | ||
58 | - color: 'rgba(0,0,0,0)' | ||
59 | - } | ||
60 | - ]) | ||
61 | - } | ||
62 | - }, | ||
63 | - { | ||
64 | - type: 'line', | ||
65 | - smooth: false, | ||
66 | - label: { | ||
67 | - show: true, | ||
68 | - position: 'top', | ||
69 | - color: '#fff', | ||
70 | - fontSize: 12 | ||
71 | - }, | ||
72 | - lineStyle: { | ||
73 | - width: 3, | ||
74 | - type: 'solid' | ||
75 | - }, | ||
76 | - areaStyle: { | ||
77 | - opacity: 0.8, | ||
78 | - color: new graphic.LinearGradient(0, 0, 0, 1, [ | ||
79 | - { | ||
80 | - offset: 0, | ||
81 | - color: chartColorsSearch[defaultTheme][4] | ||
82 | - }, | ||
83 | - { | ||
84 | - offset: 1, | ||
85 | - color: 'rgba(0,0,0,0)' | ||
86 | - } | ||
87 | - ]) | ||
88 | - } | ||
89 | - } | ||
90 | - ] | 61 | + series: [seriesItem, seriesItem] |
91 | } | 62 | } |
92 | 63 | ||
93 | export default class Config extends PublicConfigClass implements CreateComponentType { | 64 | export default class Config extends PublicConfigClass implements CreateComponentType { |
@@ -12,13 +12,13 @@ | @@ -12,13 +12,13 @@ | ||
12 | </template> | 12 | </template> |
13 | 13 | ||
14 | <script setup lang="ts"> | 14 | <script setup lang="ts"> |
15 | -import { reactive, watch, PropType, onMounted } from 'vue' | 15 | +import { reactive, watch, PropType, onMounted, ref, nextTick } from 'vue' |
16 | import VChart from 'vue-echarts' | 16 | import VChart from 'vue-echarts' |
17 | import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook' | 17 | import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook' |
18 | import { use, graphic } from 'echarts/core' | 18 | import { use, graphic } from 'echarts/core' |
19 | import { CanvasRenderer } from 'echarts/renderers' | 19 | import { CanvasRenderer } from 'echarts/renderers' |
20 | import { LineChart } from 'echarts/charts' | 20 | import { LineChart } from 'echarts/charts' |
21 | -import config, { includes } from './config' | 21 | +import config, { includes, seriesItem } from './config' |
22 | import { mergeTheme } from '@/packages/public/chart' | 22 | import { mergeTheme } from '@/packages/public/chart' |
23 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | 23 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
24 | import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index' | 24 | import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index' |
@@ -27,6 +27,7 @@ import { useChartDataFetch } from '@/hooks' | @@ -27,6 +27,7 @@ import { useChartDataFetch } from '@/hooks' | ||
27 | import { isPreview, colorGradientCustomMerge } from '@/utils' | 27 | import { isPreview, colorGradientCustomMerge } from '@/utils' |
28 | import dataJson from './data.json' | 28 | import dataJson from './data.json' |
29 | import { useFullScreen } from '../../utls/fullScreen' | 29 | import { useFullScreen } from '../../utls/fullScreen' |
30 | +import isObject from 'lodash/isObject' | ||
30 | 31 | ||
31 | const props = defineProps({ | 32 | const props = defineProps({ |
32 | themeSetting: { | 33 | themeSetting: { |
@@ -106,12 +107,12 @@ watch( | @@ -106,12 +107,12 @@ watch( | ||
106 | } | 107 | } |
107 | ) | 108 | ) |
108 | 109 | ||
109 | -watch( | ||
110 | - () => props.chartConfig.option.dataset, | ||
111 | - () => { | ||
112 | - option.value = props.chartConfig.option | ||
113 | - } | ||
114 | -) | 110 | +// watch( |
111 | +// () => props.chartConfig.option.dataset, | ||
112 | +// () => { | ||
113 | +// option.value = props.chartConfig.option | ||
114 | +// } | ||
115 | +// ) | ||
115 | let seriesDataNum = -1 | 116 | let seriesDataNum = -1 |
116 | let seriesDataMaxLength = 0 | 117 | let seriesDataMaxLength = 0 |
117 | let intervalInstance: any = null | 118 | let intervalInstance: any = null |
@@ -194,7 +195,36 @@ const updateVChart = (newData: any) => { | @@ -194,7 +195,36 @@ const updateVChart = (newData: any) => { | ||
194 | }) | 195 | }) |
195 | } | 196 | } |
196 | 197 | ||
197 | -const {vChartRef} = useChartDataFetch(props.chartConfig, useChartEditStore, (newData) => { | 198 | +const replaceMergeArr = ref<string[]>() |
199 | + | ||
200 | +// dataset 无法变更条数的补丁 | ||
201 | +watch( | ||
202 | + () => props.chartConfig.option.dataset, | ||
203 | + (newData: { dimensions: any }, oldData) => { | ||
204 | + try { | ||
205 | + option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes) | ||
206 | + if (!isObject(newData) || !('dimensions' in newData)) return | ||
207 | + if (Array.isArray(newData?.dimensions)) { | ||
208 | + const seriesArr = [] | ||
209 | + for (let i = 0; i < newData.dimensions.length - 1; i++) { | ||
210 | + seriesArr.push(seriesItem) | ||
211 | + } | ||
212 | + replaceMergeArr.value = ['series'] | ||
213 | + props.chartConfig.option.series = seriesArr | ||
214 | + nextTick(() => { | ||
215 | + replaceMergeArr.value = [] | ||
216 | + }) | ||
217 | + } | ||
218 | + } catch (error) { | ||
219 | + console.log(error) | ||
220 | + } | ||
221 | + }, | ||
222 | + { | ||
223 | + deep: false | ||
224 | + } | ||
225 | +) | ||
226 | + | ||
227 | +const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, newData => { | ||
198 | // addPieInterval(newData) | 228 | // addPieInterval(newData) |
199 | updateVChart(newData) | 229 | updateVChart(newData) |
200 | }) | 230 | }) |
@@ -11,7 +11,7 @@ export const hideAsideComponentsObj = { | @@ -11,7 +11,7 @@ export const hideAsideComponentsObj = { | ||
11 | Lines: [ | 11 | Lines: [ |
12 | 'VLineCommon', //折线图 | 12 | 'VLineCommon', //折线图 |
13 | 'VLineGradients', //双折线渐变面积图 | 13 | 'VLineGradients', //双折线渐变面积图 |
14 | - 'ExternalVCOverrideLineGradients' //重写双折线渐变面积图 | 14 | + // 'ExternalVCOverrideLineGradients' //重写双折线渐变面积图 |
15 | ], | 15 | ], |
16 | Pies: [ | 16 | Pies: [ |
17 | 'VPieCircle' //饼图-环形 | 17 | 'VPieCircle' //饼图-环形 |
@@ -22,7 +22,10 @@ export const hideAsideComponentsObj = { | @@ -22,7 +22,10 @@ export const hideAsideComponentsObj = { | ||
22 | Mores: [ | 22 | Mores: [ |
23 | 'VProcess', //NaiveUI-进度 | 23 | 'VProcess', //NaiveUI-进度 |
24 | 'VImage', //图片 | 24 | 'VImage', //图片 |
25 | - 'VImageCarousel' //轮播图 | 25 | + 'VImageCarousel', //轮播图 |
26 | + 'VVideo', //视频 | ||
27 | + 'VIframe', //远程网页 | ||
28 | + 'VWaterPolo' //水球图 | ||
26 | ], | 29 | ], |
27 | Texts: [ | 30 | Texts: [ |
28 | 'VTextGradient', //渐变文字 | 31 | 'VTextGradient', //渐变文字 |
@@ -35,7 +38,7 @@ export const hideAsideComponentsObj = { | @@ -35,7 +38,7 @@ export const hideAsideComponentsObj = { | ||
35 | 'VLineLinearSingle', //单折线渐变图 | 38 | 'VLineLinearSingle', //单折线渐变图 |
36 | 'VLineGradientSingle', //单折线渐变面积图 | 39 | 'VLineGradientSingle', //单折线渐变面积图 |
37 | 'VLineGradients', //双折线渐变面积图 | 40 | 'VLineGradients', //双折线渐变面积图 |
38 | - 'ExternalVCOverrideLineGradients', //重写双折线渐变面积图 | 41 | + // 'ExternalVCOverrideLineGradients', //重写双折线渐变面积图 |
39 | 'VPieCircle', //饼图-环形 | 42 | 'VPieCircle', //饼图-环形 |
40 | 'VMapBase', //地图(可选省份) | 43 | 'VMapBase', //地图(可选省份) |
41 | 'VProcess', //NaiveUI-进度 | 44 | 'VProcess', //NaiveUI-进度 |
@@ -45,6 +48,7 @@ export const hideAsideComponentsObj = { | @@ -45,6 +48,7 @@ export const hideAsideComponentsObj = { | ||
45 | 'VVideo', //视频 | 48 | 'VVideo', //视频 |
46 | 'VIframe', //远程网页 | 49 | 'VIframe', //远程网页 |
47 | 'VImage', //图片 | 50 | 'VImage', //图片 |
48 | - 'VImageCarousel' //轮播图 | 51 | + 'VImageCarousel', //轮播图 |
52 | + 'VWaterPolo' //水球图 | ||
49 | ] | 53 | ] |
50 | } | 54 | } |