代码之家  ›  专栏  ›  技术社区  ›  underfrankenwood

VISX避免Y轴上的浮动

  •  0
  • underfrankenwood  · 技术社区  · 4 年前

    如何避免Y轴上的浮动?

    笔记 :我不想使用 Math.round 因为它破坏了轴。VISX中有什么类似于图表的东西吗。js公司 precision

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  0
  •   Cassiopea    4 年前

    可以在不修改基础数据和打断轴的情况下格式化轴记号,使用

    VisX基于d3。js,你可以在这里了解它的tickFormat函数: https://github.com/d3/d3-scale/blob/main/README.md#continuous_tickFormat

    // function, that controls tick format
    
    const formatValue = (value) => Math.round(value)
    
    // Axis code in you component <SVG /> container
    
    <AxisLeft
        tickTextFill={'#EDF2F7'}
        stroke={'#EDF2F7'}
        tickStroke={'#EDF2F7'}
        scale={yourScale}
        tickFormat={formatValue}
    />