使用 react-chartjs-2,创建条形图如下。我正在尝试将图例制作成方形而不是默认矩形。
我应用了 boxWidth: 10 如下但它不起作用,是否有任何其他可能的替代方法来生成方形图例
const sample_data = {
labels: ['Item1', 'Item2'],
datasets: [
{
data: [10, 10, 50],
borderWidth: 1,
backgroundColor: 'yellow',
},
{ data: [20, 20, 20],
borderWidth: 1,
backgroundColor: 'green'
},
],
};
const sample_options = {
responsive: true,
legend: {
boxWidth: 10, // Also 0 doesn't make any change
},
...
};
<Bar data={sample_data} options={sample_options} />;