wx-f2
wx-f2 copied to clipboard
chart.getPosition(obj)不兼容
chart.getPosition(obj)不兼容
// 绘制柱状图文本
let offset = -5
let canvas2 = chart.get('canvas')
console.log(canvas2.addGroup())
let group = canvas2.addGroup()
let shapes = {}
data.map(function (obj) {
let point = chart.getPosition(obj)
console.log(point)
let text = group.addShape('text', {
attrs: {
x: point.x,
y: point.y + offset,
text: 1213,
textAlign: 'center',
textBaseline: 'bottom',
fill: '#808080'
}
})
shapes[obj.year] = text // 缓存该 shape, 便于后续查找
})
报错信息
VM7410:1 TypeError: Cannot read property 'scales' of undefined
at e.n.getXScale (BlockChart.vue:1)
at e.n.getXScale (BlockChart.vue:1)
at e.n.getPosition (BlockChart.vue:1)
at BlockChart.vue:78
at Array.map (<anonymous>)
at VueComponent.initChart (BlockChart.vue:77)
at boundFn (index.js:189)
at t.<anonymous> (f2-canvas.js? [sm]:86)
at WAService.js:13
at Array.forEach (<anonymous>)
console.error @ VM7410:1
n.forEach @ appservice?t=1536495892997:3089
d @ appservice?t=1536495892997:3089
k.onmessage @ appservice?t=1536495892997:3089
同问
同问,这个导致chart.showTooltip也没法使用
同问
贴下版本和对应可复现demo
chart.getPosition(obj)不兼容
// 绘制柱状图文本 let offset = -5 let canvas2 = chart.get('canvas') console.log(canvas2.addGroup()) let group = canvas2.addGroup() let shapes = {} data.map(function (obj) { let point = chart.getPosition(obj) console.log(point) let text = group.addShape('text', { attrs: { x: point.x, y: point.y + offset, text: 1213, textAlign: 'center', textBaseline: 'bottom', fill: '#808080' } }) shapes[obj.year] = text // 缓存该 shape, 便于后续查找 })
报错信息
VM7410:1 TypeError: Cannot read property 'scales' of undefined at e.n.getXScale (BlockChart.vue:1) at e.n.getXScale (BlockChart.vue:1) at e.n.getPosition (BlockChart.vue:1) at BlockChart.vue:78 at Array.map (<anonymous>) at VueComponent.initChart (BlockChart.vue:77) at boundFn (index.js:189) at t.<anonymous> (f2-canvas.js? [sm]:86) at WAService.js:13 at Array.forEach (<anonymous>) console.error @ VM7410:1 n.forEach @ appservice?t=1536495892997:3089 d @ appservice?t=1536495892997:3089 k.onmessage @ appservice?t=1536495892997:3089
绘制柱状图文本的代码需要放到 chart.render() 后面