Commit 85a4712c authored by 郭铭瑶's avatar 郭铭瑶 🤘

使my-pie返回实例

parent 65494cdb
......@@ -23,7 +23,8 @@ export default defineComponent({
default: null,
},
},
setup(props) {
emits: ['init'],
setup(props, ctx) {
const defaultOption: PieOption = {
backgroundColor: 'transparent',
tooltip: {
......@@ -54,8 +55,14 @@ export default defineComponent({
defaultOption,
defaultSeriesItem
)
onMounted(() => initChart(props.dataset, props.option))
watchEffect(() => initChart(props.dataset, props.option))
onMounted(() => {
const instance: any = initChart(props.dataset, props.option)
instance && ctx.emit('init', instance)
})
watchEffect(() => {
const instance: any = initChart(props.dataset, props.option)
instance && ctx.emit('init', instance)
})
return {
chartRef,
}
......
......@@ -202,7 +202,10 @@ const useChartGenerate = <T>(
* @param dataset 数据集
* @param option 自定义图表配置
*/
const initChart = (dataset: DatasetComponentOption, option?: ECOption) => {
const initChart = (
dataset: DatasetComponentOption,
option?: ECOption
): any => {
if (!myChart.value) return
const config =
(defaultSeriesItem as any).type === 'radar'
......@@ -214,6 +217,7 @@ const useChartGenerate = <T>(
: defaultConfig(defaultOption, defaultSeriesItem, dataset)
mergeOptions(config, option)
myChart.value.setOption(transLinearColorOption(config), true)
return myChart.value
}
return { chartRef, initChart }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment