问题:
我创建了一个反应组件来显示条形图。看起来就是这样。
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={5.0 / 6.0}>
<BarChart
data={data}
layout="vertical"
barGap={4}
margin={{
top: 6,
right: 50,
left: 2,
bottom: 0
}}
>
<Tooltip />
<XAxis type="number" className="xaxies" dy={1}/>
<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;
这就是CSS文件的样子。
@media only screen and (min-width: 1024px) {
.subscribers-by-region-card {
margin-left: 5.5%;
margin-top: -5.1%;
width: 107%;
height: 4% !important;
margin-bottom: 13px;
padding-bottom: -20%
}
.subscribers-by-region-card-title {
font-weight: 700;
text-align: left;
padding-left: 3%
}
}
@media only screen and (min-width: 308px) and (max-width: 1024px) {
}
@media only screen and (min-width: 1666px) {
.subscribers-by-region-card {
margin-left: 6.8%;
margin-top: 5%;
width: 115.5%;
height: 50% !important;
}
.subscribers-by-region-card-title {
font-weight: 700;
text-align: center;
}
.xaxies{
margin-top: -50%
}
}
我要做的是在设备更改时更改条形尺寸并显示y轴。而且我也想删除x轴和图表之间的空间,如下图所示。
在大屏幕上打开时,它应该增加条形图和图表尺寸,并且还应该显示y轴。有人可以帮我解决这些问题吗?
这是我的代码生成的shart的样子。