首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用react-vis以x轴( MM-DD)格式显示日期

使用react-vis以x轴( MM-DD)格式显示日期
EN

Stack Overflow用户
提问于 2019-05-08 20:13:14
回答 1查看 2.2K关注 0票数 2

我正在尝试在我的项目中实现react-vis。我需要显示基于日期的数据。我使用了tickFormat,但它在x轴上显示了两次相同的日期。我在这里添加了几行代码。

代码语言:javascript
复制
       <XYPlot
        width={1140}
        height={440}
        >
        <LineMarkSeries
           lineStyle={{stroke: '#e0e0e0'}}
            markStyle={{stroke: '#6dc6c1'}}
            style={{
                strokeWidth: '2px'
            }}
            strokeStyle="solid"
            data={[
                {
                    x: Date.parse("05/05/2019"),
                    y: 0
                },
                {
                    x: Date.parse("05/12/2019"),
                    y: 12
                },
                {
                    x: Date.parse("05/13/2019"),
                    y: 16
                }
            ]}
         />
          <XAxis
            attr="x"
            attrAxis="y"
            orientation="bottom"
            tickFormat={function tickFormat(d){return 
                           moment(d).format("MMM DD")}}
            tickLabelAngle={0}
         />
        <YAxis />
    </XYPlot>
EN

回答 1

Stack Overflow用户

发布于 2019-06-20 03:00:49

如果您指定ordinalxType,它将使用您的x值作为刻度标签(例如:类似于条形图)。因此,您不必使用Date.parse对x值进行冗余转换。

代码语言:javascript
复制
<XYPlot
  width={1140}
  height={440}
  xType='ordinal'
>
    <LineMarkSeries
      lineStyle={{stroke: '#e0e0e0'}}
      markStyle={{stroke: '#6dc6c1'}}
      style={{ strokeWidth: '2px' }}
      strokeStyle="solid"
      data={[
        {
          x: "05/05/2019",
          y: 0
        },
        {
          x: "05/12/2019",
          y: 12
        },
        {
          x: "05/13/2019",
          y: 16
        }
      ]}
    />
    <XAxis />
</XYPlot>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56040548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档