加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – react native:x轴时间列的胜利图表格式

发布时间:2020-12-15 05:07:10 所属栏目:百科 来源:网络整理
导读:我目前正在使用Victory图表,并且在处理向x轴添加时间方面存在问题.我需要显示一个折线图,显示y轴中0到1(百分比)之间的数字和x轴中的时间.我已经审查了他们的文档,并尝试了几种方案来使x坐标显示时间,但我没有看到数据库中的数据数据是如何被格式化为可接受的
我目前正在使用Victory图表,并且在处理向x轴添加时间方面存在问题.我需要显示一个折线图,显示y轴中0到1(百分比)之间的数字和x轴中的时间.我已经审查了他们的文档,并尝试了几种方案来使x坐标显示时间,但我没有看到数据库中的数据数据是如何被格式化为可接受的,以便随时显示.我希望时间以“10:30 AM”等格式显示.我想格式化x轴数据并在x轴和y轴上添加标签.我怎么做到这一点?我应该使用Date对象还是字符串格式可以接受基于时间的数据?字符串可以接受哪种比例?

我目前的图表jsx标签如下:

constructor (props) {
    super(props);
    this.state = {
        data: props.data,zoomDomain: { x: [new Date(2010,1,1),new Date(2050,1)] }
    }
}

handleZoom(domain) {
    this.setState({ zoomDomain: domain });
}

<VictoryChart width={400} height={500} theme={VictoryTheme.material} scale={{x:"time",y:"linear"}}
                      containerComponent={
                          <VictoryZoomContainer
                              zoomDimension="x"
                              zoomDomain={this.state.zoomDomain}
                              onZoomDomainChange={this.handleZoom}
                          />
                      }>
                    <VictoryAxis
                        tickFormat={(x) => {
                          return (new Date(x)).getFullYear();
                        }}
                        orientation="bottom"
                    />
                    <VictoryAxis dependentAxis
                                 tickFormat={(y) => y / 10}
                                 orientation="left"
                    />
                    <VictoryLine
                        groupComponent={<VictoryClipContainer clipPadding={{ top: 5,right: 10 }}/>}
                        style={{ data: { stroke: "#c43a31",strokeWidth: 5,strokeLinecap: "round" } }}
                        data={this.state.data}
                        x="x"
                        y="y"/>
                </VictoryChart>

更新:我想以不同的方式尝试这个,因为时间不适合我.我想尝试只显示月份和年份.有没有办法实现这一点,所以如果大多数时间介于3月5日和6日之间,它将显示月份之间的界限,但是线条将显示在3月到4月之间?

这就是我的图表最终看起来像:

您可以在VictoryChart订单中使用 tickFormat prop tickFormat组件执行此类操作,并根据需要添加您自己的格式化程序.
<VictoryAxis
      tickFormat={(x) => new Date(x).getHours() + ':' + new Date(x).getMinutes()}
  />

对于y轴,您可以添加另一个带有指定过滤器的tickFormat

<VictoryAxis dependentAxis
     tickFormat={(y) => y / 20}
/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读