我正在使用 react-chart-js 中的水平条(https://github.com/reactchartjs/react-chartjs-2/blob/react16/example/src/charts/HorizontalBar.js),如下所示,
const data = {
label: ["graph"],
datasets: [
{
label: "A",
backgroundColor: "red",
data: [50],
},
{
label: "B",
backgroundColor: "yellow",
data: [10],
},
],
};
const chartOptions = {
scales: {
xAxes: [
{
stacked: true,
barPercentage: 0.2,
},
],
yAxes: [
{
stacked: true,
barPercentage: 0.2,
},
],
},
};
和
<div>
<HorizontalBar data={data} options={chartOptions}/>
</div>
我尝试将高度直接应用于 div 或水平条以限制画布的放大,但它仍然可以解决。是否可以分别为图表的画布提供高度和宽度。