bizcharts:通过 scale 中 tickCount 设置纵坐标的刻度个数时,有时会不生效,请问该如何解决?

新手上路,请多包涵

我设置 tickCount 刻度数为5。下图中,有一个值为 8001,然后纵轴的刻度数就变为了 6 个了。
image.png

源码如下:

import React from "react";
import {
  G2,
  Chart,
  Geom,
  Axis,
  Tooltip,
  Coord,
  Label,
  Legend,
  View,
  Guide,
  Shape,
  Facet,
  Util
} from "bizcharts@3.5.9";

class Basiccolumn extends React.Component {
  render() {
    const data = [
      {
        year: "1951 年",
        sales: 38
      },
      {
        year: "1952 年",
        sales: 52
      },
      {
        year: "1956 年",
        sales: 61
      },
      {
        year: "1957 年",
        sales: 8001
      },
      {
        year: "1958 年",
        sales: 48
      },
      {
        year: "1959 年",
        sales: 38
      },
      {
        year: "1960 年",
        sales: 38
      },
      {
        year: "1962 年",
        sales: 38
      }
    ];
const scale = {
  sales:{
    type:"linear",
    tickCount:5,
  },
}

    return (
      <div style={{width:"800px",height:"500px"}}>
            
        <Chart height={500}  data={data} forceFit padding={[20,40,40,47]} scale={scale}>
          <Axis name="sales" grid={{type:"line"}} />
          <Tooltip/>
          <Geom type="interval" position="year*sales" />
        </Chart>            
            

      </div>
    );
  }
}

ReactDOM.render(<Basiccolumn />, mountNode)

请问这该如何解决?

阅读 4.1k
1 个回答
新手上路,请多包涵

tickCount不好使的。计算出数据的最大值,然后根据最大值计算出一个数组。将数组赋值给scale中的ticks,ticks接收一个数组用于指定坐标轴上的刻度点。比如需求是要6个刻度点,而计算出的最大值是500.那么就可以把数组[0,100,200,300,400,500]赋值给ticks.有点麻烦,但能实现需求

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题