【问题标题】:How to position all dates on xAxis using recharts and stretch width on 100% in React?如何在 React 中使用 recharts 和 100% 拉伸宽度来定位 xAxis 上的所有日期?
【发布时间】:2021-07-29 17:00:52
【问题描述】:

1.我想在 xAxis 上垂直定位所有日期(每 3 小时 5 天)?

2。我想在屏幕上以 100% 的宽度和 600 像素的高度拉伸图形?

<LineChart width={600} height={200} data={chartData}>
<Line type="monotone" dataKey="temp" stroke="#fc7f03" name="Temperature" unit=" °C"/>
<CartesianGrid stroke="#ccc" strokeDasharray="5 5" />
<XAxis dataKey="date" tick={{fontSize: 10, fill: 'orange'}} tickFormatter={(unixTime) => moment(unixTime).format('DD.MM - HHч.')}/>
<YAxis />
<Tooltip />
</LineChart>

Examples on recharts

【问题讨论】:

    标签: javascript reactjs recharts


    【解决方案1】:

    如果您查看他们的示例,您会发现他们有一个组件 https://recharts.org/en-US/api/ResponsiveContainer

    响应式容器

    你可以从

    “图表”

    然后像他们的例子一样使用它

    <ResponsiveContainer width="100%" height="100%">
            <LineChart
              width={500}
              height={300}
              data={data}
              margin={{
                top: 5,
                right: 30,
                left: 20,
                bottom: 5,
              }}
            >
              <CartesianGrid strokeDasharray="3 3" />
              <XAxis dataKey="name" />
              <YAxis />
              <Tooltip />
              <Legend />
              <Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
              <Line type="monotone" dataKey="uv" stroke="#82ca9d" />
            </LineChart>
          </ResponsiveContainer>
    

    您还可以为 XAxis 设置设置。

    在此处查看文档https://recharts.org/en-US/api/XAxis#tickCount

    【讨论】:

    • 你知道如何在图表上显示值,我找不到如何在 xAxis 上显示所有数据..
    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多