wx-f2 icon indicating copy to clipboard operation
wx-f2 copied to clipboard

chart.getPosition(obj)不兼容

Open secreter opened this issue 6 years ago • 5 comments

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

secreter avatar Sep 09 '18 12:09 secreter

同问

gaojing007 avatar Oct 18 '18 08:10 gaojing007

同问,这个导致chart.showTooltip也没法使用

YangLuYang avatar Dec 06 '19 08:12 YangLuYang

同问

Jaycexx avatar Mar 25 '20 04:03 Jaycexx

贴下版本和对应可复现demo

zengyue avatar Mar 25 '20 12:03 zengyue

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() 后面

lybrooks avatar Apr 29 '22 01:04 lybrooks