antvis / F2

📱📈An elegant, interactive and flexible charting library for mobile.
https://f2.antv.vision/zh
MIT License
7.89k stars 649 forks source link

在柱状图中绘制文本时,position[0]中不能包含百分号,否则显示位置不正确。 #590

Closed OPY-bbt closed 5 years ago

OPY-bbt commented 5 years ago

image

var Global = F2.Global;
  var data = [
     {category: "ER", value: 8},
     {category: "R", value: 3},
     {category:"5%蔓迪", value: 3},
     {category: "I", value: 3},
  ];
  var chart = new F2.Chart({
    id: 'mountNode',
    pixelRatio: window.devicePixelRatio
  });
  chart.source(data);
  chart.coord({
    transposed: true
  });
  chart.axis('action', {
    line: Global._defaultAxis.line,
    grid: null
  });
  chart.axis('value', {
    line: null,
    grid: Global._defaultAxis.grid,
    label: function label(text, index, total) {
      var textCfg = {};
      if (index === 0) {
        textCfg.textAlign = 'left';
      } else if (index === total - 1) {
        textCfg.textAlign = 'right';
      }
      return textCfg;
    }
  });
  chart.interval().position('category*value');

  // 绘制文本
  data.map(function(obj) {
    chart.guide().text({
      position: [obj.category, obj.value],
      content: obj.value,
      style: {
        textAlign: 'start'
      },
      offsetX: 10
    });
  });
  chart.render();
simaQ commented 5 years ago

https://github.com/antvis/f2/blob/19a3cc6c9f8061675a8a8acbca6cdb60fd2bd390/src/component/guide/base.js#L52 这段代码解析的问题,以为 position 支持传入百分比,比如 '45%',是个 BUG。需要修复下

OPY-bbt commented 5 years ago

终于修复了。。。 想问一下pr里的修改是不是少了一个&?

position[0].indexOf('%') !== -1 & !isNaN(position[0].slice(0, -1))
simaQ commented 5 years ago

不好意思,丢人了...

OPY-bbt commented 5 years ago

不好意思,丢人了...

谁都有手误的时候。。。