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

The width of label in yAxis dose not be set an appropriate width when the 'textAlign' has been set 'start'.The width is set about 20px directly.I can only justify the offsetX to minus value to fix it.Could G2 fit the label width automatically rather than to set offsetX manually? #4050

Closed
1 task
blackwidowX opened this issue Jul 25, 2022 · 1 comment

Comments

@blackwidowX
Copy link

blackwidowX commented Jul 25, 2022

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://github.com/antvis/g2

Steps to reproduce

import G2 from "@antv/g2";

const data = [
  { type: '汽车', value: 34 },
  { type: '建材家居', value: 85 },
  { type: '住宿旅游', value: 103 },
  { type: '交通运输与仓储邮政', value: 142 },
  { type: '建筑房地产', value: 251 },
  { type: '教育', value: 367 },
  { type: 'IT 通讯电子', value: 491 },
  { type: '社会公共管理', value: 672 },
  { type: '医疗卫生', value: 868 },
  { type: '金融保险', value: 1234 }
];
const chart = new G2.Chart({
  container: 'container',
  forceFit: true,
  height: 500,
  padding: [ 20, 40, 50, 124 ]
});
chart.source(data, {
  value: {
    max: 1300,
    min: 0,
    nice: false,
    alias: '销量(百万)'
  }
});
chart.axis('type', {
  label: {
    // If the textAlign is set 'start', I can just set the offsetX to a minus value to see all text of y.
    offsetX: -100,
    textStyle: {
      textAlign: 'start',
      fill: '#8d8d8d',
      fontSize: 12
    }
  },
  tickLine: {
    alignWithLabel: false,
    length: 0
  },
  line: {
    lineWidth: 0
  }
});
chart.axis('value', {
  label: null,
  title: {
    offset: 30,
    textStyle: {
      fontSize: 12,
      fontWeight: 300
    }
  }
});
chart.legend(false);
chart.coord().transpose();
chart.interval().position('type*value').size(26)
  .opacity(1)
  .label('value', {
    textStyle: {
      fill: '#8d8d8d'
    },
    offset: 10
  });
chart.render();
Environment Info
g2 4.2.5
System -
Browser -

look at the annotation of the code snippet.

@hustcc
Copy link
Member

hustcc commented Sep 13, 2022

chart.axis('type', {
  label: {
    // If the textAlign is set 'start', I can just set the offsetX to a minus value to see all text of y.
    offsetX: 0,
    textStyle: {
      textAlign: 'end', // use `end`
      fill: '#8d8d8d',
      fontSize: 12
    }
  },
  // ...

@hustcc hustcc closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants