用于比较不同类别之间的数值大小,是最常用的数据可视化图表
const config = {
data: basicData,
xField: 'region',
yField: 'value',
padding: [40, 12, 30, 20], // 减少左侧和底部padding,让柱状图紧贴Y轴和X轴
color: '#5B8FF9',
columnWidthRatio: 0.5,
columnStyle: { radius: [4, 4, 0, 0] },
xAxis: {
label: {
autoRotate: false,
rotate: 0,
style: { fontSize: 11, fill: '#1D1D1F', textAlign: 'center' },
},
line: { style: { stroke: '#E8E8ED' } },
tickLine: null,
},
yAxis: {
label: {
style: { fontSize: 11, fill: '#1D1D1F' },
formatter: (v) => v.toLocaleString()
},
grid: { line: { style: { stroke: '#E8E8ED', lineDash: [4, 4] } } },
line: null,
tickLine: null,
},
label: {
position: 'top',
offset: 8,
style: { fill: '#1D1D1F', fontSize: 11 }
},
legend: false,
};
| 参数 | 值 | 说明 |
|---|---|---|
padding | [40, 12, 30, 20] | 图表内边距 [上, 右, 下, 左] |
| 容器高度 | 240px | 标准图表高度 |
columnWidthRatio | 0.5 | 柱体宽度占比 |
| 参数 | X轴值 | Y轴值 |
|---|---|---|
| label.fontSize | 11px | 11px |
| label.fill | #1D1D1F | #1D1D1F |
| line.stroke | #E8E8ED | null |
| grid.line | null | #E8E8ED [4,4] |
const config = {
data: basicData,
xField: 'region',
yField: 'value',
padding: [40, 12, 30, 20], // 减少左侧和底部padding,让柱状图紧贴Y轴和X轴
color: '#5AD8A6',
columnWidthRatio: 0.5,
columnStyle: { radius: [4, 4, 0, 0] },
label: {
position: 'top',
offset: 6,
style: { fill: '#1D1D1F', fontSize: 11 }
},
xAxis: { label: { style: { fontSize: 11, fill: '#1D1D1F' } } },
yAxis: {
label: { style: { fontSize: 11, fill: '#1D1D1F' } },
grid: { line: { style: { stroke: '#E8E8ED', lineDash: [4, 4] } } }
},
};
const config = {
data: groupedData,
xField: 'region',
yField: 'value',
seriesField: 'type',
isGroup: true,
padding: [40, 12, 30, 20], // 减少左侧和底部padding,让柱状图紧贴Y轴和X轴
color: ['#5B8FF9', '#5AD8A6'],
columnWidthRatio: 0.6,
columnStyle: { radius: [3, 3, 0, 0] },
xAxis: { label: { style: { fontSize: 11, fill: '#1D1D1F' } } },
yAxis: {
label: { style: { fontSize: 11, fill: '#1D1D1F' } },
grid: { line: { style: { stroke: '#E8E8ED', lineDash: [4, 4] } } }
},
legend: {
position: 'top-right',
itemSpacing: 20,
itemName: {
style: { fontSize: 12, fill: '#1D1D1F' },
},
marker: {
symbol: 'circle',
style: { r: 5 },
},
},
};