2 Commitit f179d6e0b4 ... 8e1769b599

Tekijä SHA1 Viesti Päivämäärä
  jiangwh 8e1769b599 Merge branch 'main' of http://47.116.201.158:3000/ligb/invest-research-frontend 1 päivä sitten
  jiangwh 3546487196 fix(financing): 双Y轴图表零点对齐并修正刻度浮点漂移 1 päivä sitten
1 muutettua tiedostoa jossa 21 lisäystä ja 4 poistoa
  1. 21 4
      web-app/src/views/fundamental/financing/charts.js

+ 21 - 4
web-app/src/views/fundamental/financing/charts.js

@@ -125,8 +125,22 @@ export function loanStructureOption(d) {
 }
 
 // ============== 图4 近1年票据融资额 vs 10年国债(双 Y 轴) ==============
+// 左轴范围按数据取整;右轴下限按 0 点与左轴对齐反推(右轴上限固定 rightMax)
+function alignedAxis(leftVals, step, rightMax) {
+  const vMin = Math.min(0, ...leftVals)
+  const vMax = Math.max(step, ...leftVals)
+  const min = vMin < 0 ? -Math.ceil((-vMin * 1.1) / step) * step : 0
+  const max = Math.ceil((vMax * 1.1) / step) * step
+  const rightMin = min < 0 ? +(((rightMax * min) / max).toFixed(2)) : 0
+  return { min, max, rightMin }
+}
+
+// 右轴标签格式化:消除 alignTicks 带来的浮点漂移(如 -0.003 → 0)
+const pctLabel = { color: C.mut, fontSize: 11, formatter: (v) => String(+v.toFixed(2)) }
+
 export function billVsBond10Option(d) {
   const cats = (d.categories || []).map((x) => String(x).slice(2, 7))
+  const ax = alignedAxis(d.bill12m || [], 5000, 5)
   return {
     tooltip: { ...tipOpt, trigger: 'axis' },
     legend: {
@@ -141,12 +155,13 @@ export function billVsBond10Option(d) {
     yAxis: [
       {
         type: 'value', name: '亿元', position: 'left',
+        min: ax.min, max: ax.max,
         ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14 }),
       },
       {
         type: 'value', name: '%', position: 'right',
-        min: 0, max: 5,
-        ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14 }),
+        min: ax.rightMin, max: 5, alignTicks: true,
+        ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14, axisLabel: pctLabel }),
       },
     ],
     series: [
@@ -179,6 +194,7 @@ export function billVsBond10Option(d) {
 // ============== 图5 M1 同比 vs 10年国债(双 Y 轴) ==============
 export function m1VsBond10Option(d) {
   const cats = (d.categories || []).map((x) => String(x).slice(2, 7))
+  const ax = alignedAxis(d.m1Yoy || [], 5, 5)
   return {
     tooltip: { ...tipOpt, trigger: 'axis' },
     legend: {
@@ -190,12 +206,13 @@ export function m1VsBond10Option(d) {
     yAxis: [
       {
         type: 'value', name: '%', position: 'left',
+        min: ax.min, max: ax.max,
         ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14 }),
       },
       {
         type: 'value', name: '%', position: 'right',
-        min: 0, max: 5,
-        ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14 }),
+        min: ax.rightMin, max: 5, alignTicks: true,
+        ...axisStyle({ nameTextStyle: { color: C.mut, fontSize: 10 }, nameGap: 14, axisLabel: pctLabel }),
       },
     ],
     series: [