6
Version
5.1.1
Steps to reproducevue3环境下创建组件如下:
<template>
<div class="chart" :id="chartId"></div>
</template>
<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted, ref } from 'vue'
import * as echarts from 'echarts'
export default defineComponent({
name: 'pieChart',
props: {
chartData: {
type: Array
}
},
setup(props) {
const chartId = `barChart${Math.random()}`
const chart = ref<any>()
const chartDatas = reactive({
// dataList: props.chartData
dataList: [
{ title: 'Matcha Latte', count1: 43.3, '2016': 85.8, '2017': 93.7 },
{ title: 'Milk Tea', count1: 83.1, '2016': 73.4, '2017': 55.1 },
{ title: 'Cheese Cocoa', count1: 86.4, '2016': 65.2, '2017': 82.5 },
{ title: 'Walnut Brownie', count1: 72.4, '2016': 53.9, '2017': 39.1 }
]
})
console.log(props)
onMounted(() => {
// console.log(echarts)
chart.value = echarts.init(document.getElementById(chartId) as HTMLDivElement)
chart.value.setOption({
legend: {
orient: 'vertical',
left: '75%',
top: '30%'
},
xAxis: {
type: 'category',
axisTick: { alignWithLabel: true }
},
yAxis: {
type: 'value'
},
dataZoom: [
{
type: 'slider',
start: 50,
end: 100,
realtime: true,
height: 7
}
],
dataset: { source: chartDatas.dataList },
series: [
{
name: '',
type: 'bar',
encode: {
x: 'title',
y: 'count1'
}
}
]
})
})
return {
chartId,
chart,
...toRefs(chartDatas)
}
}
})
</script>
<style lang="stylus" scoped>
.chart
width 100%
height 100%
</style>
页面中引用组件
可调整图表显示数据范围
What is actually happening?柱状图的报错如下:
barPolar.js:63 Uncaught TypeError: Cannot read property 'type' of undefined
at barPolar.js:63
at GlobalModel2.<anonymous> (Global.js:661)
at Array.forEach (<anonymous>)
at each (util.js:206)
at GlobalModel2.eachSeriesByType (Global.js:657)
at Object.barLayoutPolar (barPolar.js:61)
at Object.overallReset (util.js:311)
at Task2.overallTaskReset [as _reset] (Scheduler.js:460)
at Task2._doReset (task.js:202)
at Task2.perform (task.js:117)
报错语句为:
if (seriesModel.coordinateSystem.type !== 'polar') {
return;
}
此处的 seriesModel.coordinateSystem
为 undefined
。
这是为什么呢?