From afec6b8ef19ce4adc0b86303f5b47c2a6aaf5898 Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Sat, 31 May 2025 00:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9B=BE=E8=A1=A8y=E8=BD=B4?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E5=8F=B3=E4=BE=A7=EF=BC=8C=E4=BC=9A?= =?UTF-8?q?=E5=9C=A8=E7=A7=BB=E5=8A=A8=E7=AB=AF=E8=A2=AB=E9=81=AE=E6=8C=A1?= =?UTF-8?q?=E4=B8=80=E9=83=A8=E5=88=86=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=AE=A1=E7=AE=97=E6=9C=80=E5=A4=A7=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=9C=80=E8=BF=91=E5=89=8D=E4=B8=80=E5=A4=A9=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E6=97=A5=E6=9C=9F=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=BD=93=E5=A4=A9=E6=AD=A3=E5=A5=BD=E6=B2=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8F=88=E6=98=AF=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E5=A4=A9=EF=BC=8C=E4=B8=B4=E7=95=8C=E5=80=BC=E4=BC=9A=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/customEcharts/size1920/index.vue | 14 +++++++++----- src/components/customEcharts/size375/index.vue | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/customEcharts/size1920/index.vue b/src/components/customEcharts/size1920/index.vue index 1708411..13edb98 100644 --- a/src/components/customEcharts/size1920/index.vue +++ b/src/components/customEcharts/size1920/index.vue @@ -84,6 +84,10 @@ const initEcharts = (data) => { // title: { // text: 'FiEE, Inc. Stock Price History', // }, + grid: { + left: '8%', // 或 '2%',根据实际情况调整 + right: '12%', // 给右侧y轴留空间,数值可根据y轴label宽度调整 + }, tooltip: { trigger: 'axis', axisPointer: { @@ -326,15 +330,15 @@ function findClosestDateIndexDescLeft(data, targetDateStr) { let left = 0, right = data.length - 1 const target = new Date(targetDateStr).getTime() - let res = -1 // 默认返回-1(找不到) + let res = -1 while (left <= right) { const mid = Math.floor((left + right) / 2) const midTime = new Date(data[mid].date).getTime() - if (midTime < target) { - right = mid - 1 // 向左搜索,因为我们要找的是小于等于目标日期的最近一天 + if (midTime > target) { + left = mid + 1 // mid 比目标新,往更旧的方向找 } else { - res = mid // 记录当前找到的索引 - left = mid + 1 // 向右搜索,因为更早的日期在数组后面 + res = mid // mid <= target,记录下来,继续往更新的方向找 + right = mid - 1 } } return res diff --git a/src/components/customEcharts/size375/index.vue b/src/components/customEcharts/size375/index.vue index dc53cd4..ed22a10 100644 --- a/src/components/customEcharts/size375/index.vue +++ b/src/components/customEcharts/size375/index.vue @@ -84,6 +84,10 @@ const initEcharts = (data) => { // title: { // text: 'FiEE, Inc. Stock Price History', // }, + grid: { + left: '8%', // 或 '2%',根据实际情况调整 + right: '15%', // 给右侧y轴留空间,数值可根据y轴label宽度调整 + }, tooltip: { trigger: 'axis', axisPointer: { @@ -327,15 +331,15 @@ function findClosestDateIndexDescLeft(data, targetDateStr) { let left = 0, right = data.length - 1 const target = new Date(targetDateStr).getTime() - let res = -1 // 默认返回-1(找不到) + let res = -1 while (left <= right) { const mid = Math.floor((left + right) / 2) const midTime = new Date(data[mid].date).getTime() - if (midTime < target) { - right = mid - 1 // 向左搜索,因为我们要找的是小于等于目标日期的最近一天 + if (midTime > target) { + left = mid + 1 // mid 比目标新,往更旧的方向找 } else { - res = mid // 记录当前找到的索引 - left = mid + 1 // 向右搜索,因为更早的日期在数组后面 + res = mid // mid <= target,记录下来,继续往更新的方向找 + right = mid - 1 } } return res