被卡住一小会
Cannot read property 'pathes' of undefined
是events方法的错误,查询发现是this的指向问题
initChart() {
this.chart = echarts.init(document.getElementById('calendarchart'))
this.option = {
tooltip: {
},
calendar: [{
left: 'center',
top: 'middle',
cellSize: 'auto',
yearLabel: { show: false },
orient: 'vertical',
dayLabel: {
firstDay: 1,
nameMap: 'cn'
},
monthLabel: {
show: false
},
range: '2020-03'
}],
series: [{
type: 'custom',
coordinateSystem: 'calendar',
renderItem: this.renderItem,
dimensions: [null, { type: 'ordinal' }],
data: this.getVirtulData(2020)
}]
}
this.chart.setOption(this.option, true)
},
renderItem(params, api) {
var cellPoint = api.coord(api.value(0))
var cellWidth = params.coordSys.cellWidth
var cellHeight = params.coordSys.cellHeight
var value = api.value(1)
var events = value && value.split('|')
if (isNaN(cellPoint[0]) || isNaN(cellPoint[1])) {
return
}
const that = this
var group = {
type: 'group',
children: echarts.util.map(this.layouts[events.length - 1], function(itemLayout, index) {
return {
type: 'path',
shape: {
pathData: that.pathes[events[index]],
x: -8,
y: -8,
width: 16,
height: 16
},
position: [
cellPoint[0] + echarts.number.linearMap(itemLayout[0], [-0.5, 0.5], [-cellWidth / 2, cellWidth / 2]),
cellPoint[1] + echarts.number.linearMap(itemLayout[1], [-0.5, 0.5], [-cellHeight / 2 + 20, cellHeight / 2])