Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OPY-bbt opened this issue May 28, 2019 · 4 comments · Fixed by #650 or #671
Assignees
Labels
Milestone

Comments

@OPY-bbt
Copy link

OPY-bbt commented May 28, 2019

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 simaQ self-assigned this Aug 29, 2019
@simaQ simaQ added the bug label Aug 29, 2019
@simaQ
Copy link
Contributor

simaQ commented Aug 29, 2019

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

@OPY-bbt
Copy link
Author

OPY-bbt commented Aug 31, 2019

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

position[0].indexOf('%') !== -1 & !isNaN(position[0].slice(0, -1))

@simaQ
Copy link
Contributor

simaQ commented Aug 31, 2019

不好意思,丢人了...

@OPY-bbt
Copy link
Author

OPY-bbt commented Aug 31, 2019

不好意思,丢人了...

谁都有手误的时候。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants