feat: 增加宁德时代图表
This commit is contained in:
+56
@@ -361,6 +361,62 @@ export function stackedSharePoint(value, { pxPerUnit, labelColor, dy = 0, minIns
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* tooltip 彩色圆点标记。
|
||||
*
|
||||
* 为什么不直接用 ECharts 的默认 marker:折线系列的 visualDrawType 恒为 'fill'
|
||||
* (Series.js 原型默认值,只有轨迹图 / 箱线图改成 'stroke'),而空心圆折线的
|
||||
* itemStyle.color 必须是 #fff —— tooltip 取到的 marker 就是白色,在白底提示框上
|
||||
* 等于隐形。这里按系列语义色自绘标记,不依赖 ECharts 内部取色。
|
||||
*/
|
||||
export function tooltipMarker(color) {
|
||||
return `<span style="display:inline-block;width:10px;height:10px;border-radius:50%;`
|
||||
+ `background:${color};margin-right:6px;vertical-align:-1px"></span>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标准 tooltip:每一项前面带该系列语义色的圆点。
|
||||
*
|
||||
* 不能用 ECharts 默认 marker:折线系列 visualDrawType 为 'fill',
|
||||
* 而空心圆折线的 itemStyle.color 是 #fff,默认 marker 会被取成白色而在白底上隐形。
|
||||
* 取色规则:
|
||||
* - 柱:优先用该数据点自身的颜色(支持逐项着色,如按公司或国别上色)
|
||||
* - 折线:用 lineStyle.color(空心圆的 itemStyle.color 是白色,不能作语义色)
|
||||
*
|
||||
* @param {Array} series 已构造好的系列数组
|
||||
* @param {(value: number) => string} formatValue 默认数值格式化
|
||||
* @param {Object<string, (value: number) => string>} [formatBySeries] 按系列名覆盖
|
||||
* —— 柱线组合图两条序列单位不同(如 GWh 与 %)时必需
|
||||
*/
|
||||
export function tooltipOf(series, formatValue, formatBySeries) {
|
||||
const seriesColors = {};
|
||||
series.forEach((item) => {
|
||||
const color = item.lineStyle?.color ?? item.itemStyle?.color;
|
||||
if (item.name && color) seriesColors[item.name] = color;
|
||||
});
|
||||
|
||||
return {
|
||||
trigger: 'axis',
|
||||
axisPointer: { type: 'shadow' },
|
||||
textStyle: { fontFamily: FONT, fontSize: 13 },
|
||||
formatter: (params) => {
|
||||
const list = Array.isArray(params) ? params : [params];
|
||||
if (list.length === 0) return '';
|
||||
const head = `<span style="color:${PALETTE.ink};font-weight:600">`
|
||||
+ `${list[0].axisValueLabel ?? list[0].name ?? ''}</span>`;
|
||||
const body = list.map((item) => {
|
||||
const fallback = seriesColors[item.seriesName] ?? PALETTE.grey;
|
||||
const color = item.seriesType === 'bar' ? (item.color || fallback) : fallback;
|
||||
const fmt = formatBySeries?.[item.seriesName] ?? formatValue;
|
||||
const raw = item.value;
|
||||
const value = raw === null || raw === undefined || raw === '' ? '—' : fmt(raw);
|
||||
return `${tooltipMarker(color)}${item.seriesName}:${value}`;
|
||||
});
|
||||
return [head, ...body].join('<br/>');
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** 底部注释 */
|
||||
export function footnote(text) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user