mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-26 11:36:44 +08:00
RayChart组件新增watchOptions属性
This commit is contained in:
parent
a112799b42
commit
360ae3c373
@ -3,4 +3,5 @@
|
|||||||
height: var(--ray-chart-height);
|
height: var(--ray-chart-height);
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
PieChart,
|
PieChart,
|
||||||
CandlestickChart,
|
CandlestickChart,
|
||||||
ScatterChart,
|
ScatterChart,
|
||||||
|
PictorialBarChart,
|
||||||
} from 'echarts/charts' // 系列类型(后缀都为 `SeriesOption`)
|
} from 'echarts/charts' // 系列类型(后缀都为 `SeriesOption`)
|
||||||
import { LabelLayout, UniversalTransition } from 'echarts/features' // 标签自动布局, 全局过渡动画等特性
|
import { LabelLayout, UniversalTransition } from 'echarts/features' // 标签自动布局, 全局过渡动画等特性
|
||||||
import { CanvasRenderer } from 'echarts/renderers' // `echarts` 渲染器
|
import { CanvasRenderer } from 'echarts/renderers' // `echarts` 渲染器
|
||||||
@ -131,15 +132,17 @@ const RayChart = defineComponent({
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object as PropType<echarts.EChartsCoreOption>,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
success: {
|
success: {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param `chart` 实例
|
* 返回 chart 实例
|
||||||
*
|
*
|
||||||
* 渲染成功回调函数
|
* 渲染成功回调函数
|
||||||
|
*
|
||||||
|
* () => EChartsInstance
|
||||||
*/
|
*/
|
||||||
type: Function,
|
type: Function,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
@ -148,6 +151,8 @@ const RayChart = defineComponent({
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 渲染失败回调函数
|
* 渲染失败回调函数
|
||||||
|
*
|
||||||
|
* () => void
|
||||||
*/
|
*/
|
||||||
type: Function,
|
type: Function,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
@ -178,6 +183,11 @@ const RayChart = defineComponent({
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
|
watchOptions: {
|
||||||
|
/** 主动监听 options 变化 */
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const settingStore = useSetting()
|
const settingStore = useSetting()
|
||||||
@ -221,11 +231,12 @@ const RayChart = defineComponent({
|
|||||||
PieChart,
|
PieChart,
|
||||||
CandlestickChart,
|
CandlestickChart,
|
||||||
ScatterChart,
|
ScatterChart,
|
||||||
|
PictorialBarChart,
|
||||||
]) // 注册类型
|
]) // 注册类型
|
||||||
|
|
||||||
echarts.use([LabelLayout, UniversalTransition]) // 注册布局, 过度效果
|
echarts.use([LabelLayout, UniversalTransition]) // 注册布局, 过度效果
|
||||||
|
|
||||||
// 如果业务场景中需要 `svg` 渲染器, 手动导入渲染器后使用该行代码即可
|
// 如果业务场景中需要 `svg` 渲染器, 手动导入渲染器后使用该行代码即可(不过为了体积考虑, 移除了 SVG 渲染器)
|
||||||
// echarts.use([props.canvasRender ? CanvasRenderer : SVGRenderer])
|
// echarts.use([props.canvasRender ? CanvasRenderer : SVGRenderer])
|
||||||
echarts.use([CanvasRenderer]) // 注册渲染器
|
echarts.use([CanvasRenderer]) // 注册渲染器
|
||||||
|
|
||||||
@ -300,6 +311,8 @@ const RayChart = defineComponent({
|
|||||||
props.success?.(echartInstance)
|
props.success?.(echartInstance)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
props.error?.()
|
props.error?.()
|
||||||
|
|
||||||
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,6 +382,17 @@ const RayChart = defineComponent({
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (props.watchOptions) {
|
||||||
|
watch(
|
||||||
|
() => props.watchOptions,
|
||||||
|
() => {
|
||||||
|
const options = useMergeOptions()
|
||||||
|
|
||||||
|
echartInstance?.setOption(options)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onBeforeMount(async () => {
|
||||||
await registerChartCore()
|
await registerChartCore()
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user