Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用react vis以(MM-DD)格式在x轴上显示日期_Reactjs_React Vis - Fatal编程技术网

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

Reactjs 使用react vis以(MM-DD)格式在x轴上显示日期,reactjs,react-vis,Reactjs,React Vis,我试图在我的项目中实现react-vis。我需要显示基于日期的数据。我使用的是tickFormat,但它在x轴上显示了两次相同的日期。我在这里添加了几行代码 <XYPlot width={1140} height={440} > <LineMarkSeries lineStyle={{stroke: '#e0e0e0'}} markStyle={{stro

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

       <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>

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

<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>


维护时刻。格式(MM-DD)在数据数组中也使用相同的日期格式。我尝试过,但不起作用。显示此错误(错误:属性cx:预期长度,“NaN”。)我认为数据数组中可能不支持这种格式。这将生成一个图表,其中所有日期都相邻,而不管两个日期之间经过了多少时间。