This commit is contained in:
Cindy Chang
2024-08-02 13:24:15 +08:00
parent 86cfb409c3
commit 4ba7961a5a
6 changed files with 12 additions and 17 deletions

View File

@@ -177,7 +177,6 @@ export function yTimeRange(data, yAmount, yMax) {
* @returns {numver} x index
*/
export function getXIndex(data, xValue) {
let closestElement = data[0]; // 假定第一个元素是最接近的
let closestIndex = xValue; // 假定第一个元素的索引是 0
let smallestDifference = Math.abs(xValue - data[0]); // 初始差值设为第一个元素与目标数的差值
@@ -185,7 +184,6 @@ export function getXIndex(data, xValue) {
let difference = Math.abs(xValue - data[i]);
if (difference <= smallestDifference) {
closestElement = data[i];
closestIndex = i;
smallestDifference = difference;
}