echarts icon indicating copy to clipboard operation
echarts copied to clipboard

fix(label): axisLabel precision causes floating-point error in number…

Open im0505 opened this issue 8 months ago • 0 comments

Brief Information

This pull request is in the type of:

  • [x] bug fixing
  • [ ] new feature
  • [ ] others

What does this PR do?

Removing 2 additional digit when to use toFixed for precision

https://github.com/apache/echarts/blob/f4c244c8975e4b3c33afd26fb51d603917bff930/src/scale/helper.ts#L101-L104

Try demo

option = {
  grid: {
    left: 300,
  },
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
  },
  yAxis: {
    type: 'value',
    interval: 0.0670572916666667,
    max:  0.1341145833333334,
    min: -0.2011718750000001,
    splitNumber: 5
  },
  series: [
    {
      data: [
        0.060546845,
        0.0928, 
        0.00097656, 
        0.02389, 
        0.006238
        ],
      type: 'bar'
    }
  ]
};

Fixed issues

https://github.com/apache/echarts/issues/21036

Details

Before: What was the problem?

image toFixed can have residual floating-point noise. https://github.com/apache/echarts/issues/5986 seems to be covered for now.

After: How does it behave after the fixing?

image

Document Info

One of the following should be checked.

  • [x] This PR doesn't relate to document changes
  • [ ] The document should be updated later
  • [ ] The document changes have been made in apache/echarts-doc#xxx

Misc

ZRender Changes

  • [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

  • [ ] Please squash the commits into a single one when merging.

Other information

im0505 avatar Jun 16 '25 03:06 im0505