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

左边的序号怎么从0开始 或者下移一行 #281

Open
Years0315 opened this issue Sep 23, 2021 · 3 comments
Open

左边的序号怎么从0开始 或者下移一行 #281

Years0315 opened this issue Sep 23, 2021 · 3 comments

Comments

@Years0315
Copy link

序号1正好和标题对应 我想和我的数据对应

@kaierwen
Copy link

原因:

TableData类有个方法getYSequenceFormat用来格式化Y轴(也就是左边序号那一列)

/**
  * 获取Y序号列文字格式化
  * @return  Y序号列文字格式化
  */
  public ISequenceFormat getYSequenceFormat() {
    if(YSequenceFormat == null){
        YSequenceFormat = new NumberSequenceFormat();
    }
    return YSequenceFormat;
  }

如果没设置YSequenceFormat,会使用默认的NumberSequenceFormat,NumberSequenceFormat的实现如下

public class NumberSequenceFormat extends BaseSequenceFormat{
    @Override
    public String format(Integer position) {
        return String.valueOf(position);
    }
}

position的值是从1开始的,所以序号是从1开始

解决:

调用TableData.setYSequenceFormat(ISequenceFormat YSequenceFormat)方法设置ISequenceFormat即可,可以复写NumberSequenceFormat的format方法实现

Java版本:

tableData.setYSequenceFormat(new NumberSequenceFormat() {
    @Override
    public String format(Integer integer) {
        return (integer-1)+"";
    }
});

Kotlin版本:

tableData.ySequenceFormat = object : NumberSequenceFormat() {
     override fun format(position: Int): String {
         return (position - 1).toString()
     }
}

@Lee-swifter
Copy link

刚要查这个问题,就找到了这里。 kaerwen 给出的答案真是正解。感谢大佬

@kaierwen
Copy link

刚要查这个问题,就找到了这里。 kaerwen 给出的答案真是正解。感谢大佬

突然收到邮箱提醒,都不记得自己曾经回答过这个问题,能帮助到别人还是很开心的

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

3 participants