Files
smart-fin-chart/js/charts/twoline.js
T
2026-08-23 21:23:41 +08:00

65 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { col } from '../csv.js';
import {
PALETTE, FONT, axisCommon, categoryAxis, titleStyle, legendStyle,
lineSeries, footnote, watermarks, LAYOUT,
} from '../theme.js';
/**
* 图 3:毛利率 vs 非国际净利率,两条线的简版对照
* 从 margin.csv 复用同一份数据,只挑两列
*/
export function twoLineChart(rows, { width, height }) {
return {
backgroundColor: '#fff',
title: { ...titleStyle, text: '毛利率与非国际净利率(半年与年度)' },
legend: {
...legendStyle,
top: LAYOUT.legendTop,
data: ['毛利率', '非国际归母净利率'].map(name => ({
name,
icon: 'emptyCircle', // 全部折线图
})),
},
grid: { left: 72, right: 48, top: LAYOUT.gridTop, bottom: 62 },
tooltip: {
trigger: 'axis',
valueFormatter: (v) => `${v}%`,
textStyle: { fontFamily: FONT },
},
xAxis: { ...categoryAxis, data: col(rows, 'period') },
yAxis: {
...axisCommon,
type: 'value',
name: '比率(%',
nameLocation: 'middle',
nameGap: 46,
nameTextStyle: { color: PALETTE.grey, fontSize: 13, fontFamily: FONT },
min: -5,
max: 80,
interval: 25,
axisLabel: { ...axisCommon.axisLabel, formatter: '{value}%' },
},
series: [
lineSeries({
name: '毛利率',
data: col(rows, 'gross_margin'),
color: PALETTE.navy,
labelPosition: 'top',
formatter: (p) => `${p.value}%`,
width: 3.5,
}),
lineSeries({
name: '非国际归母净利率',
data: col(rows, 'non_gaap_net_margin'),
color: PALETTE.coral,
labelPosition: 'top',
formatter: (p) => `${p.value}%`,
}),
],
graphic: [
...watermarks(width, height),
footnote('示例数据 | @思考的Joey'),
],
};
}