131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
import { col } from '../csv.js';
|
||
import {
|
||
PALETTE, FONT, axisCommon, periodAxis, titleStyle, legendStyle,
|
||
footnote, watermarks, LAYOUT,
|
||
} from '../theme.js';
|
||
|
||
/**
|
||
* 泡泡玛特品类收入结构图
|
||
* 堆叠柱状图展示各品类的收入占比和增长
|
||
*/
|
||
export function categoryChart(rows, { width, height }) {
|
||
// 过滤掉表头行("品类"那一行)
|
||
const dataRows = rows.filter(r => r.period && r.period !== '品类');
|
||
const periods = col(dataRows, 'period');
|
||
|
||
return {
|
||
backgroundColor: '#fff',
|
||
title: {
|
||
...titleStyle,
|
||
text: '泡泡玛特品类收入结构(2024H1-2025H2)',
|
||
subtext: '单位:亿元',
|
||
},
|
||
legend: {
|
||
...legendStyle,
|
||
top: LAYOUT.legendTop,
|
||
data: ['毛绒', '手办', 'MEGA', '衍生品及其他'].map(name => ({
|
||
name,
|
||
icon: 'rect', // 全部是堆叠柱状图
|
||
})),
|
||
},
|
||
grid: { left: 78, right: 56, top: LAYOUT.gridTop, bottom: 90 },
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
axisPointer: { type: 'shadow' },
|
||
textStyle: { fontFamily: FONT },
|
||
formatter: (params) => {
|
||
let result = `<b>${params[0].axisValue}</b><br/>`;
|
||
let total = 0;
|
||
params.forEach(p => {
|
||
total += p.value;
|
||
result += `${p.marker}${p.seriesName}: ${p.value.toFixed(2)} 亿元<br/>`;
|
||
});
|
||
result += `<b>合计: ${total.toFixed(2)} 亿元</b>`;
|
||
return result;
|
||
},
|
||
},
|
||
xAxis: { ...periodAxis, data: periods },
|
||
yAxis: {
|
||
...axisCommon,
|
||
type: 'value',
|
||
name: '收入(亿元)',
|
||
nameLocation: 'middle',
|
||
nameGap: 52,
|
||
nameTextStyle: { color: PALETTE.grey, fontSize: 13, fontFamily: FONT },
|
||
min: 0,
|
||
max: 250,
|
||
interval: 50,
|
||
},
|
||
series: [
|
||
{
|
||
name: '毛绒',
|
||
type: 'bar',
|
||
stack: 'category',
|
||
data: col(dataRows, 'plush'),
|
||
itemStyle: { color: PALETTE.coral },
|
||
emphasis: { focus: 'series' },
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
color: '#fff',
|
||
fontSize: 12,
|
||
fontFamily: FONT,
|
||
formatter: (p) => (p.value > 15 ? p.value.toFixed(1) : ''),
|
||
},
|
||
},
|
||
{
|
||
name: '手办',
|
||
type: 'bar',
|
||
stack: 'category',
|
||
data: col(dataRows, 'figure'),
|
||
itemStyle: { color: PALETTE.blue },
|
||
emphasis: { focus: 'series' },
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
color: '#fff',
|
||
fontSize: 12,
|
||
fontFamily: FONT,
|
||
formatter: (p) => (p.value > 15 ? p.value.toFixed(1) : ''),
|
||
},
|
||
},
|
||
{
|
||
name: 'MEGA',
|
||
type: 'bar',
|
||
stack: 'category',
|
||
data: col(dataRows, 'mega'),
|
||
itemStyle: { color: PALETTE.purple },
|
||
emphasis: { focus: 'series' },
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
color: '#fff',
|
||
fontSize: 12,
|
||
fontFamily: FONT,
|
||
formatter: (p) => (p.value > 8 ? p.value.toFixed(1) : ''),
|
||
},
|
||
},
|
||
{
|
||
name: '衍生品及其他',
|
||
type: 'bar',
|
||
stack: 'category',
|
||
data: col(dataRows, 'other'),
|
||
itemStyle: { color: PALETTE.sage },
|
||
emphasis: { focus: 'series' },
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
color: '#fff',
|
||
fontSize: 12,
|
||
fontFamily: FONT,
|
||
formatter: (p) => (p.value > 8 ? p.value.toFixed(1) : ''),
|
||
},
|
||
},
|
||
],
|
||
graphic: [
|
||
...watermarks(width, height),
|
||
footnote('数据来源:泡泡玛特财报 | @思考的Joey'),
|
||
],
|
||
};
|
||
}
|