2022-01-15 21:05:11 +08:00
|
|
|
<template>
|
2022-03-10 21:35:49 +08:00
|
|
|
<VChart :theme="themeColor" :option="option.options" autoresize />
|
2022-01-15 21:05:11 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-03-10 21:35:49 +08:00
|
|
|
import { computed, PropType, watch, reactive, watchEffect } from 'vue';
|
2022-02-02 18:17:45 +08:00
|
|
|
import VChart from 'vue-echarts'
|
|
|
|
import { use, graphic } from 'echarts/core'
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
import { LineChart } from 'echarts/charts'
|
2022-02-24 17:23:20 +08:00
|
|
|
import config, { includes } from './config'
|
2022-02-21 21:16:44 +08:00
|
|
|
import { mergeTheme } from '@/packages/public/chart'
|
2022-03-09 20:27:53 +08:00
|
|
|
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
2022-03-10 20:54:02 +08:00
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
2022-03-10 21:35:49 +08:00
|
|
|
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
|
2022-01-15 21:05:11 +08:00
|
|
|
|
2022-02-02 18:17:45 +08:00
|
|
|
const props = defineProps({
|
2022-02-21 19:45:11 +08:00
|
|
|
themeSetting: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
themeColor: {
|
|
|
|
type: Object,
|
2022-02-06 01:04:05 +08:00
|
|
|
required: true
|
|
|
|
},
|
2022-02-24 17:23:20 +08:00
|
|
|
chartConfig: {
|
2022-02-02 18:17:45 +08:00
|
|
|
type: Object as PropType<config>,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
})
|
2022-01-15 21:05:11 +08:00
|
|
|
|
2022-02-02 18:17:45 +08:00
|
|
|
use([
|
|
|
|
CanvasRenderer,
|
|
|
|
LineChart,
|
|
|
|
GridComponent,
|
|
|
|
TooltipComponent,
|
2022-03-09 20:27:53 +08:00
|
|
|
LegendComponent
|
2022-02-02 18:17:45 +08:00
|
|
|
])
|
2022-01-15 21:05:11 +08:00
|
|
|
|
2022-03-10 20:54:02 +08:00
|
|
|
const chartEditStore = useChartEditStore()
|
2022-03-10 21:35:49 +08:00
|
|
|
const option = reactive({
|
|
|
|
options: {}
|
|
|
|
})
|
|
|
|
|
|
|
|
watchEffect(()=> {
|
|
|
|
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
|
})
|
2022-03-10 20:54:02 +08:00
|
|
|
|
2022-03-10 21:35:49 +08:00
|
|
|
// 渐变色处理
|
|
|
|
watch(()=>chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: string) => {
|
|
|
|
const themeColor = (chartColorsSearch as any)[newColor] || chartColorsSearch[defaultTheme]
|
|
|
|
props.chartConfig.option.series[0].lineStyle.color.colorStops[0].color = themeColor[0]
|
|
|
|
props.chartConfig.option.series[0].lineStyle.color.colorStops[1].color = themeColor[1]
|
|
|
|
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
2022-02-02 18:17:45 +08:00
|
|
|
})
|
|
|
|
</script>
|