x轴上的Nivo Line Formatting时间刻度

问题描述 投票:0回答:1

我想使用我使用@nivo/line图表的反应库的时间格式化折线图的X轴

 axisBottom={{
   tickValues: 3,
   tickRotation: 90,
   format: (values) => `${getRequiredDateFormat(values, 'MMMM-DD')}`, // using momentjs to format   
   legendOffset: -80,
   legendPosition: 'start',
}}

Chart output

仅希望每个月显示一次,根据数据显示一次。

CodeSandbox Link在这里尝试

javascript reactjs d3.js graph axis-labels
1个回答
1
投票

您可以创建一个包含所有x轴日期的新数组,如果该日期出现多次,则只显示一次。

这是一个可行的示例-

https://codesandbox.io/s/quirky-leftpad-dwmb9?file=/src/App.js&fbclid=IwAR1dZoKls-dVowdVRoN3pZd8INsHgc2egNdcNLkj3n0nDqMpJQIJdK6vyQ8

© www.soinside.com 2019 - 2024. All rights reserved.