[英]Set min/max date for date in Recharts.js
我正在使用 Recharts.js 在我的網站中顯示圖表數據。 但是我想設置 XAxis 的最小值/最大值,這是日期類型,但嘗試使用域對我不起作用:
<ResponsiveContainer width="100%" height={200}>
<BarChart
width={400}
height={200}
data={data}
margin={{
top: 20,
left: 5,
bottom: 5,
right: 5
}}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="time" tickFormatter={timeStr => moment(timeStr).format(timeFormat)} />
<YAxis dateKey="count" type="number" allowDecimals={false} tickCount={10} />
<Tooltip formatter={(value, name) => [value, startCase(name)]} />
<Bar dataKey="count" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
關鍵部分是:
<XAxis dataKey="time" tickFormatter={timeStr => moment(timeStr).format(timeFormat)} />
domain={['2018-01-01', '2019-12-31']}
domain={['2018-01-01 00:00:00', '2019-12-31 00:00:00']}
domain={['2018-01-01T00:00:00.000+09:00', '2019-12-31T23:59:59.999+09:00']}
domain={[new Date('2018-01-01'), new Date('2019-12-31')]}
domain={[new Date('2018-01-01').getTime(), new Date('2019-12-31').getTime()]}
domain={[moment('2018-01-01').format('YYYY-MM-DD'), moment('2019-12-31').format('YYYY-MM-DD')]}
仍然第一個日期設置為最早日期,最后一個日期設置為最晚日期。 我在這里缺少什么?
domain
適用於“數字”類型軸的數字類型;
當您提供帶引號的日期時,它就成為一個類別;
您需要在 unix epoch 中轉換date
,即從 1970 年 1 月 1 日開始的秒數;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.