126 lines
3.3 KiB
JavaScript
126 lines
3.3 KiB
JavaScript
import {
|
||
PALETTE, FONT, titleStyle, footnote, watermarks,
|
||
LAYOUT, } from '../theme.js';
|
||
|
||
/**
|
||
* 泡泡玛特区域渠道同比增速图(2026H1 vs 2025H1)
|
||
* 垂直条形图,每个渠道使用统一颜色
|
||
*/
|
||
export function regionChannelYoyChart(rows, { width, height }) {
|
||
// 按区域和渠道重组数据
|
||
const regions = ['中国', '海外', '亚太', '美洲', '欧洲及其他'];
|
||
const channels = ['线下渠道', '线上渠道', '批发及其他'];
|
||
|
||
// 构建数据映射
|
||
const dataMap = {};
|
||
rows.forEach(row => {
|
||
const key = `${row.region}_${row.channel}`;
|
||
dataMap[key] = row.yoy;
|
||
});
|
||
|
||
// 为每个渠道构建数据系列
|
||
const seriesData = channels.map(channel => {
|
||
return regions.map(region => {
|
||
const key = `${region}_${channel}`;
|
||
return dataMap[key] || 0;
|
||
});
|
||
});
|
||
|
||
// 为每个渠道定义统一的颜色
|
||
const channelColors = {
|
||
'线下渠道': PALETTE.navy,
|
||
'线上渠道': PALETTE.coral,
|
||
'批发及其他': PALETTE.sage,
|
||
};
|
||
|
||
return {
|
||
backgroundColor: '#fff',
|
||
title: {
|
||
...titleStyle,
|
||
text: '泡泡玛特区域渠道同比增速(2026H1 vs 2025H1)',
|
||
subtext: '各区域渠道同比增速对比',
|
||
top: 18,
|
||
},
|
||
legend: {
|
||
data: channels.map(name => ({ name, icon: 'rect' })), // 全部柱状图
|
||
top: LAYOUT.legendTop,
|
||
itemGap: 32,
|
||
textStyle: { fontFamily: FONT, fontSize: 13 },
|
||
},
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
axisPointer: { type: 'shadow' },
|
||
textStyle: { fontFamily: FONT },
|
||
formatter: (params) => {
|
||
let result = `<b>${params[0].axisValue}</b><br/>`;
|
||
params.forEach(p => {
|
||
const value = p.value;
|
||
const sign = value >= 0 ? '+' : '';
|
||
result += `${p.marker}${p.seriesName}: ${sign}${value.toFixed(1)}%<br/>`;
|
||
});
|
||
return result;
|
||
},
|
||
},
|
||
grid: {
|
||
left: 80,
|
||
right: 60,
|
||
top: 145,
|
||
bottom: 90,
|
||
containLabel: false,
|
||
},
|
||
xAxis: {
|
||
type: 'category',
|
||
data: regions,
|
||
axisLine: {
|
||
show: true,
|
||
lineStyle: { color: '#333', width: 2 }
|
||
},
|
||
axisTick: { show: false },
|
||
axisLabel: {
|
||
fontFamily: FONT,
|
||
fontSize: 12,
|
||
color: '#333',
|
||
},
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
axisLine: { show: false },
|
||
axisTick: { show: false },
|
||
splitLine: {
|
||
show: true,
|
||
lineStyle: { color: '#e8e8e8', width: 1 }
|
||
},
|
||
axisLabel: {
|
||
formatter: '{value}%',
|
||
fontFamily: FONT,
|
||
fontSize: 12,
|
||
color: '#8c8c8c',
|
||
},
|
||
},
|
||
series: channels.map((channel, idx) => ({
|
||
name: channel,
|
||
type: 'bar',
|
||
data: seriesData[idx],
|
||
itemStyle: { color: channelColors[channel] },
|
||
barWidth: 47,
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
formatter: (params) => {
|
||
const value = params.value;
|
||
const sign = value >= 0 ? '+' : '';
|
||
return `${sign}${value.toFixed(1)}%`;
|
||
},
|
||
fontFamily: FONT,
|
||
fontSize: 12,
|
||
color: '#fff',
|
||
fontWeight: 'bold',
|
||
},
|
||
})),
|
||
graphic: [
|
||
...watermarks(width, height),
|
||
footnote('数据来源:泡泡玛特财报(2026H1 vs 2025H1同比)| @思考的Joey'),
|
||
],
|
||
};
|
||
}
|