【发布时间】:2020-12-07 18:53:57
【问题描述】:
我想创建水平条形图组件,我添加了type : "horizontalBar",但它仍然是垂直条形图。
我;我正在使用 chartjs 库。 这是我的图表组件
import { Bar } from "react-chartjs-2";
class Chart extends Component {
constructor(props) {
super(props);
this.state = {
type: "horizontalBar",
chartData: {
labels: ["Casa", "Marrakesh", "Agadir", "tanger", "rabat"],
datasets: [
{
label: "Population",
data: [602000, 601000, 600200, 602500, 600300],
backgroundColor: ["red", "green", "blue", "black", "purple"],
},
],
},
};
}
render() {
return (
<div>
<Bar
data={this.state.chartData}
width={100}
height={50}
options={{}}
type={"horizontalBar"}
/>
</div>
);
}
}
export default Chart;
这是应用组件:
import "./App.css";
import Chart from "./components/Charts";
function App() {
return (
<div className="App">
<Chart />
</div>
);
}
export default App;
非常感谢。
【问题讨论】:
标签: javascript reactjs charts components