Commit b9bf1223 by zhangxw

fix(venus-usedcar-quality): 车况简报折线图修改

1 parent d919b1e0
Pipeline #193 for b9bf1223 failed in 0 seconds
...@@ -339,8 +339,12 @@ const handleTrendResize = () => { ...@@ -339,8 +339,12 @@ const handleTrendResize = () => {
function setData(data: any) { function setData(data: any) {
const trends = (data as any)?.priceTrends || []; const trends = (data as any)?.priceTrends || [];
const xAxisData = Array.isArray(trends) ? trends.map((i: any) => String(i?.month ?? "")) : []; const xAxisData = Array.isArray(trends)
const seriesData = Array.isArray(trends) ? trends.map((i: any) => Number(i?.priceWan ?? 0)) : []; ? trends.map((i: any) => String(i?.month ?? ""))
: [];
const seriesData = Array.isArray(trends)
? trends.map((i: any) => Number(i?.priceWan ?? i?.price ?? i?.value ?? 0))
: [];
const numeric = seriesData.filter((n) => Number.isFinite(n)); const numeric = seriesData.filter((n) => Number.isFinite(n));
hasTrendData.value = numeric.length > 0; hasTrendData.value = numeric.length > 0;
if (!hasTrendData.value) { if (!hasTrendData.value) {
...@@ -351,8 +355,9 @@ function setData(data: any) { ...@@ -351,8 +355,9 @@ function setData(data: any) {
} }
const minVal = numeric.length > 0 ? Math.min(...numeric) : 0; const minVal = numeric.length > 0 ? Math.min(...numeric) : 0;
const maxVal = numeric.length > 0 ? Math.max(...numeric) : 0; const maxVal = numeric.length > 0 ? Math.max(...numeric) : 0;
const yMin = numeric.length > 0 ? Math.max(0, Math.floor((minVal - 0.5) * 10) / 10) : 0; const yMin = numeric.length > 0 ? Math.max(0, Math.floor(minVal)) : 0;
const yMax = numeric.length > 0 ? Math.ceil((maxVal + 0.5) * 10) / 10 : 1; let yMax = numeric.length > 0 ? Math.ceil(maxVal) : 1;
if (yMax <= yMin) yMax = yMin + 1;
trendChart?.dispose(); trendChart?.dispose();
trendChart = echarts.init(trendChartRef.value, undefined, { renderer: "canvas" }); trendChart = echarts.init(trendChartRef.value, undefined, { renderer: "canvas" });
...@@ -363,18 +368,24 @@ function setData(data: any) { ...@@ -363,18 +368,24 @@ function setData(data: any) {
return s; return s;
}; };
const formatWanText = (raw: unknown) => { const formatValueText = (raw: unknown) => {
const n = Number(raw); const n = Number(raw);
if (!Number.isFinite(n)) return "-"; if (!Number.isFinite(n)) return "-";
const fixed = n.toFixed(1); const fixed = n.toFixed(2);
return fixed.endsWith(".0") ? fixed.slice(0, -2) : fixed; if (fixed.endsWith(".00")) return fixed.slice(0, -3);
if (fixed.endsWith("0")) return fixed.slice(0, -1);
return fixed;
}; };
const gridLeft = 8;
trendChart.setOption({ trendChart.setOption({
grid: { left: 44, right: 12, top: 12, bottom: 24, containLabel: true }, grid: { left: gridLeft, right: 12, top: 12, bottom: 24, containLabel: true },
tooltip: { tooltip: {
trigger: "axis", trigger: "axis",
triggerOn: "click", triggerOn: "click",
confine: true,
alwaysShowContent: true,
backgroundColor: "#ffffff", backgroundColor: "#ffffff",
borderColor: "transparent", borderColor: "transparent",
extraCssText: "box-shadow: 0 6px 18px rgba(0,0,0,0.12); border-radius: 8px; padding: 10px 12px;", extraCssText: "box-shadow: 0 6px 18px rgba(0,0,0,0.12); border-radius: 8px; padding: 10px 12px;",
...@@ -383,13 +394,26 @@ function setData(data: any) { ...@@ -383,13 +394,26 @@ function setData(data: any) {
type: "line", type: "line",
lineStyle: { color: "rgba(0,0,0,0.18)", width: 1 }, lineStyle: { color: "rgba(0,0,0,0.18)", width: 1 },
}, },
position: (point: any, _params: any, _dom: any, _rect: any, size: any) => {
const [x, y] = point as [number, number];
const [contentWidth, contentHeight] = size.contentSize as [number, number];
const [viewWidth, viewHeight] = size.viewSize as [number, number];
const left = Math.min(Math.max(0, x - contentWidth / 2), viewWidth - contentWidth);
const top = Math.min(Math.max(0, y - contentHeight - 12), viewHeight - contentHeight);
return [left, top];
},
formatter: (params: any) => { formatter: (params: any) => {
const first = Array.isArray(params) ? params[0] : params; const first = Array.isArray(params) ? params[0] : params;
const month = formatMonthLabel(first?.axisValue ?? ""); const idx = Number(first?.dataIndex);
const value = formatWanText(first?.data); const yearMonth =
Number.isFinite(idx) && trends[idx]
? String((trends[idx] as any)?.yearMonth ?? (trends[idx] as any)?.year_month ?? "")
: "";
const month = yearMonth || formatMonthLabel(first?.axisValue ?? "");
const value = formatValueText(first?.data);
return `<div style="line-height: 18px;"> return `<div style="line-height: 18px;">
<div style="font-weight: 600; margin-bottom: 2px;">${month}</div> <div style="font-weight: 600; margin-bottom: 2px;">${month}</div>
<div>本车预估价值: ${value}万</div> <div>本车预估价值: ${value}</div>
</div>`; </div>`;
}, },
}, },
...@@ -411,7 +435,11 @@ function setData(data: any) { ...@@ -411,7 +435,11 @@ function setData(data: any) {
fontSize: 10, fontSize: 10,
margin: 10, margin: 10,
align: "right", align: "right",
formatter: (v: unknown) => formatWanText(v), formatter: (v: unknown) => {
const n = Number(v);
if (!Number.isFinite(n)) return "-";
return String(Math.round(n));
},
}, },
splitLine: { lineStyle: { color: "#f0f0f0" } } splitLine: { lineStyle: { color: "#f0f0f0" } }
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!