如何清除图表中Xaxis和垂直图表之间的填充,并且颜色不正确?

时间:2019-03-15 06:17:57

标签: reactjs recharts

问题:

我正在使用React应用程序中的图表创建图表组件。

这是我的代码。

import React, { Component, PureComponent } from "react";

import { Card, CardBody, CardTitle } from "reactstrap";
import {
  Bar,
  BarChart,
  Tooltip,
  XAxis,
  YAxis,
  ResponsiveContainer,
  Cell,
  LabelList
} from "recharts";

import "./SubcribersByRegion.css";

const colors = [
  "#138185",
  "#26a0a7",
  "#65d3da",
  "#79d69f",
  "#cbe989",
  "#ebf898",
  "#f9ec86",
  "#fad144",
  "#ec983d",
  "#d76c6c"
];

const data = [
  {
    name: "Page A",
    pv: 2400,
    amt: 2400
  },
  {
    name: "Page B",
    pv: 1398,
    amt: 2210
  },
  {
    name: "Page C",
    pv: 9800,
    amt: 2290
  },
  {
    name: "Page D",
    pv: 3908,
    amt: 2000
  },
  {
    name: "Page E",
    pv: 4800,
    amt: 2181
  },
  {
    name: "Page F",
    pv: 3800,
    amt: 2500
  },
  {
    name: "Page G",
    pv: 4300,
    amt: 2100
  },
  {
    name: "Page H",
    pv: 4300,
    amt: 2100
  },
  {
    name: "Page I",
    pv: 4300,
    amt: 2100
  },
  {
    name: "Page J",
    pv: 4300,
    amt: 2100
  }
];

class SubcribersByRegion extends Component {
  render() {
    return (
      <div>
        <Card className="subscribers-by-region-card">
          <CardTitle className="subscribers-by-region-card-title">
            Subscribers by Region
          </CardTitle>
          <CardBody>
            <ResponsiveContainer width="100%" height="100%" aspect={6.5 / 8.9}>
              <BarChart
                data={data}
                layout="vertical"
                barGap={4}
                margin={{
                  top: 27,
                  right: 5,
                  left: 5,
                  bottom: 0
                }}
              >
                <Tooltip />
                <XAxis className="xaxies" />
                <Bar
                  dataKey="pv"
                  fill="#8884d8"
                  maxBarSize={10}
                >
                  {data.map((entry, index) => (
                    <Cell key={`cell-${index+1}`} fill={colors[index]} />
                  ))}
                  <LabelList dataKey="pv" position="right" />
                </Bar>
              </BarChart>
            </ResponsiveContainer>
          </CardBody>
        </Card>
      </div>
    );
  }
}

export default SubcribersByRegion;

这是我的图表现在的样子。

enter image description here

试图找到一种解决方案,为什么它不显示第一个元素的条形。而且我还尝试了许多方法,例如向Xaxias添加样式以删除xAxis与图表之间的填充。但是我找不到任何解决方案。有人可以通过修改我的代码来帮助我找到解决此问题的方法吗?谢谢!!

0 个答案:

没有答案