57 lines
1.7 KiB
Vue
Raw Normal View History

2022-01-15 21:05:11 +08:00
<template>
<VChart :theme="themeColor" :option="option.options" autoresize />
2022-01-15 21:05:11 +08:00
</template>
<script setup lang="ts">
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'
import config, { includes } from './config'
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'
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
},
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()
const option = reactive({
options: {}
})
watchEffect(()=> {
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
})
2022-03-10 20:54:02 +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>