【问题标题】:Full width tiny chart with Recharts带有 Recharts 的全宽小图表
【发布时间】:2020-12-10 10:49:40
【问题描述】:

我正在尝试使用 Recharts 将图表粘贴到我的容器的边框。我不使用任何轴,只使用直线。我无法驾驭边缘。

这里简单复制:https://jsfiddle.net/jdcpqg5k/2

import React from "react";
import {
  ComposedChart,
  ResponsiveContainer,
  Tooltip,
  Area,
  Line,
} from "recharts";

const Chart = ({ data }) => (
      <div style={{ height: 300, width: 300 }}>
        <ResponsiveContainer>
          <ComposedChart 
            data={data}
            margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
          >
            <Tooltip />
            <Area type="monotone" dataKey="count" />
            <Line type="monotone" dataKey="total" />
          </ComposedChart>
        </ResponsiveContainer>
      </div>
  );

一个肮脏的解决方法是按如下方式设置边距:

<ComposedChart
    data={data}
    margin={{ top: 0, right: -15, left: -15, bottom: 0 }}
>
    <Area type="monotone" dataKey="total" />
</ComposedChart>

但它没有响应。

【问题讨论】:

    标签: reactjs recharts


    【解决方案1】:

    图表周围的空间来自容器的填充。将 &lt;ResponsiveContainer&gt; 的填充设置为 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 2018-11-14
      • 1970-01-01
      • 2016-03-03
      • 2012-02-07
      相关资源
      最近更新 更多