71 lines
1.9 KiB
Vue
Raw Normal View History

2022-01-15 21:05:11 +08:00
<template>
2022-03-11 10:22:54 +08:00
<VChart :theme="themeColor" :option="option.options" autoresize />
2022-01-15 21:05:11 +08:00
</template>
<script setup lang="ts">
2022-03-11 10:22:54 +08:00
import { reactive, watchEffect, watch, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import config, { includes } from './config'
import { mergeTheme } from '@/packages/public/chart'
2022-03-11 10:22:54 +08:00
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
2022-01-15 21:05:11 +08:00
const props = defineProps({
themeSetting: {
type: Object,
required: true
},
themeColor: {
type: Object,
required: true
},
chartConfig: {
type: Object as PropType<config>,
required: true
}
})
2022-01-15 21:05:11 +08:00
use([
CanvasRenderer,
LineChart,
GridComponent,
TooltipComponent,
LegendComponent,
])
2022-03-11 10:22:54 +08:00
const chartEditStore = useChartEditStore()
2022-01-15 21:05:11 +08:00
2022-03-11 10:22:54 +08:00
const option = reactive({
options: {}
})
2022-03-11 10:22:54 +08:00
watchEffect(()=> {
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
})
// 渐变色处理
watch(()=>chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => {
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
props.chartConfig.option.series.forEach((value: any, index: number) => {
value.areaStyle.color = new graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: themeColor[3]
},
{
offset: 1,
color: 'rgba(0,0,0, 0)'
}
])
themeColor[index]
})
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
},
{
immediate: true
})
</script>