|
@ -19,8 +19,28 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
|
|
|
|
|
|
// 日期-作为x轴 |
|
|
// 日期-作为x轴 |
|
|
let dateArray = barAndLineData.map(subArray => subArray[0]) |
|
|
let dateArray = barAndLineData.map(subArray => subArray[0]) |
|
|
// k线,取前四个即可 |
|
|
|
|
|
let kLineDataArray = KlineData.map(subArray => subArray.slice(1, 5)) |
|
|
|
|
|
|
|
|
// k线数据格式:['2025/04/24', 250.5, 259.51, 249.2, 259.54, 274.899, 0.685, 258.354] |
|
|
|
|
|
// 原始数据:索引1=开盘价, 索引2=收盘价, 索引3=最低价, 索引4=最高价 |
|
|
|
|
|
// ECharts candlestick需要:[开盘, 收盘, 最低, 最高] |
|
|
|
|
|
let kLineDataArray = KlineData.map(subArray => [ |
|
|
|
|
|
subArray[1], // 开盘价 |
|
|
|
|
|
subArray[2], // 收盘价 |
|
|
|
|
|
subArray[3], // 最低价 |
|
|
|
|
|
subArray[4] // 最高价 |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
// 计算K线数据的最小值,用于设置y轴起始值 |
|
|
|
|
|
let allKlineValues = [] |
|
|
|
|
|
kLineDataArray.forEach(item => { |
|
|
|
|
|
if (Array.isArray(item) && item.length >= 4) { |
|
|
|
|
|
// K线数据格式:[开盘价, 收盘价, 最低价, 最高价] |
|
|
|
|
|
allKlineValues.push(item[0], item[1], item[2], item[3]) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// 找到最小值并向下取整到10的整数倍 |
|
|
|
|
|
let minValue = Math.min(...allKlineValues.filter(val => typeof val === 'number' && !isNaN(val))) |
|
|
|
|
|
let yAxisMin = Math.floor(minValue / 10) * 10 |
|
|
// 红线,取第二个值 |
|
|
// 红线,取第二个值 |
|
|
let redLineDataArray = barAndLineData.map(subArray => subArray[1]) |
|
|
let redLineDataArray = barAndLineData.map(subArray => subArray[1]) |
|
|
// 色块数据格式化 |
|
|
// 色块数据格式化 |
|
@ -157,24 +177,34 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
|
|
|
|
|
|
if (param.seriesType === 'candlestick') { |
|
|
if (param.seriesType === 'candlestick') { |
|
|
// ECharts candlestick的value格式:[开盘, 收盘, 最低, 最高] |
|
|
// ECharts candlestick的value格式:[开盘, 收盘, 最低, 最高] |
|
|
// 但param.value可能包含额外信息,需要从原始数据中获取 |
|
|
|
|
|
let dataIndex = param.dataIndex |
|
|
|
|
|
let candlestickData = kLineDataArray[dataIndex] |
|
|
|
|
|
|
|
|
let candlestickData = param.value |
|
|
|
|
|
|
|
|
|
|
|
// 确保数据有效性 |
|
|
|
|
|
if (!Array.isArray(candlestickData) || candlestickData.length < 4) { |
|
|
|
|
|
return '' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let openPrice = candlestickData[1] // 开盘价 |
|
|
|
|
|
let closePrice = candlestickData[2] // 收盘价 |
|
|
|
|
|
let lowPrice = candlestickData[3] // 最低价 |
|
|
|
|
|
let highPrice = candlestickData[4] // 最高价 |
|
|
|
|
|
|
|
|
|
|
|
// 确保所有价格都是有效数字 |
|
|
|
|
|
if (typeof openPrice !== 'number' || typeof closePrice !== 'number' || |
|
|
|
|
|
typeof lowPrice !== 'number' || typeof highPrice !== 'number') { |
|
|
|
|
|
return '' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let openPrice = candlestickData[0] // 开盘价 |
|
|
|
|
|
let closePrice = candlestickData[1] // 收盘价 |
|
|
|
|
|
let lowPrice = candlestickData[2] // 最低价 |
|
|
|
|
|
let highPrice = candlestickData[3] // 最高价 |
|
|
|
|
|
let priceChange = closePrice - openPrice |
|
|
let priceChange = closePrice - openPrice |
|
|
let changePercent = ((priceChange / openPrice) * 100).toFixed(2) |
|
|
let changePercent = ((priceChange / openPrice) * 100).toFixed(2) |
|
|
let changeColor = priceChange >= 0 ? '#14b143' : '#ef232a' // 互换颜色:上涨绿色,下跌红色 |
|
|
|
|
|
|
|
|
let changeColor = priceChange >= 0 ? '#14b143' : '#ef232a' // 互换颜色:上涨红色,下跌绿色 |
|
|
|
|
|
|
|
|
result += `<div style="margin-bottom: 6px;">` |
|
|
result += `<div style="margin-bottom: 6px;">` |
|
|
result += `<div style="color: #fff; font-weight: bold;">${param.seriesName}</div>` |
|
|
result += `<div style="color: #fff; font-weight: bold;">${param.seriesName}</div>` |
|
|
result += `<div style="color: #fff;">开盘: ${openPrice.toFixed(2)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">收盘: ${closePrice.toFixed(2)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">最低: ${lowPrice.toFixed(2)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">最高: ${highPrice.toFixed(2)}</div>` |
|
|
|
|
|
|
|
|
result += `<div style="color: #fff;">开盘: ${openPrice.toFixed(1)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">收盘: ${closePrice.toFixed(1)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">最低: ${lowPrice.toFixed(1)}</div>` |
|
|
|
|
|
result += `<div style="color: #fff;">最高: ${highPrice.toFixed(1)}</div>` |
|
|
result += `<div style="color: ${changeColor};">涨跌: ${priceChange >= 0 ? '+' : ''}${priceChange.toFixed(2)} (${changePercent}%)</div>` |
|
|
result += `<div style="color: ${changeColor};">涨跌: ${priceChange >= 0 ? '+' : ''}${priceChange.toFixed(2)} (${changePercent}%)</div>` |
|
|
result += `</div>` |
|
|
result += `</div>` |
|
|
} else if (param.seriesName === '红线') { |
|
|
} else if (param.seriesName === '红线') { |
|
@ -183,7 +213,6 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
result += `<div style="color: ${color}; margin-bottom: 4px;">${param.seriesName}: ${value}</div>` |
|
|
result += `<div style="color: ${color}; margin-bottom: 4px;">${param.seriesName}: ${value}</div>` |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
return result |
|
|
return result |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
@ -251,7 +280,7 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
axisPointer: { |
|
|
axisPointer: { |
|
|
link: { |
|
|
link: { |
|
|
xAxisIndex: 'all' |
|
|
xAxisIndex: 'all' |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
@ -319,6 +348,7 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
type: 'value', |
|
|
type: 'value', |
|
|
gridIndex: 0, |
|
|
gridIndex: 0, |
|
|
splitNumber: 4, |
|
|
splitNumber: 4, |
|
|
|
|
|
min: yAxisMin, // 设置y轴最小值为数据中最小值的10的整数倍 |
|
|
axisLine: { |
|
|
axisLine: { |
|
|
lineStyle: { |
|
|
lineStyle: { |
|
|
color: 'white' // y轴坐标轴颜色 |
|
|
color: 'white' // y轴坐标轴颜色 |
|
@ -331,9 +361,6 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
width: 50, // 宽度限制 |
|
|
width: 50, // 宽度限制 |
|
|
color: 'white', |
|
|
color: 'white', |
|
|
formatter: function (value, index) { |
|
|
formatter: function (value, index) { |
|
|
if (index === 0) { |
|
|
|
|
|
return '0' |
|
|
|
|
|
} |
|
|
|
|
|
return value.toFixed(2) |
|
|
return value.toFixed(2) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
@ -344,7 +371,6 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
type: 'dotted' // 设置网格线类型 dotted:虚线 solid:实线 |
|
|
type: 'dotted' // 设置网格线类型 dotted:虚线 solid:实线 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// min: 4, |
|
|
|
|
|
scale: true, // 不强制包含0,不然k线图底部空余太多 |
|
|
scale: true, // 不强制包含0,不然k线图底部空余太多 |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
@ -424,7 +450,7 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
{ |
|
|
{ |
|
|
type: 'slider', |
|
|
type: 'slider', |
|
|
xAxisIndex: [0, 1, 2], |
|
|
xAxisIndex: [0, 1, 2], |
|
|
start: 70, |
|
|
|
|
|
|
|
|
start: 0, |
|
|
end: 100, |
|
|
end: 100, |
|
|
show: true, |
|
|
show: true, |
|
|
bottom: 10, |
|
|
bottom: 10, |
|
@ -449,7 +475,7 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
{ |
|
|
{ |
|
|
type: 'inside', |
|
|
type: 'inside', |
|
|
xAxisIndex: [0, 1, 2], |
|
|
xAxisIndex: [0, 1, 2], |
|
|
start: 70, |
|
|
|
|
|
|
|
|
start: 0, |
|
|
end: 100, |
|
|
end: 100, |
|
|
zoomOnMouseWheel: true, |
|
|
zoomOnMouseWheel: true, |
|
|
moveOnMouseMove: true, |
|
|
moveOnMouseMove: true, |
|
@ -464,13 +490,13 @@ function initEmotionalBottomRadar(KlineData, barAndLineData) { |
|
|
xAxisIndex: 0, |
|
|
xAxisIndex: 0, |
|
|
yAxisIndex: 0, |
|
|
yAxisIndex: 0, |
|
|
itemStyle: { |
|
|
itemStyle: { |
|
|
color: '#14b143', // 上涨颜色 (绿) |
|
|
|
|
|
color0: '#ef232a', // 下跌颜色 (红) |
|
|
|
|
|
|
|
|
color: '#14b143', // 开盘价 > 收盘价时为绿色 |
|
|
|
|
|
color0: '#ef232a', // 开盘价 < 收盘价时为红色 |
|
|
borderColor: '#14b143', |
|
|
borderColor: '#14b143', |
|
|
borderColor0: '#ef232a', |
|
|
borderColor0: '#ef232a', |
|
|
normal: { |
|
|
normal: { |
|
|
color: '#14b143', // 上涨颜色 (绿) |
|
|
|
|
|
color0: '#ef232a', // 下跌颜色 (红) |
|
|
|
|
|
|
|
|
color: '#14b143', // 开盘价 > 收盘价时为绿色 |
|
|
|
|
|
color0: '#ef232a', // 开盘价 < 收盘价时为红色 |
|
|
borderColor: '#14b143', |
|
|
borderColor: '#14b143', |
|
|
borderColor0: '#ef232a', |
|
|
borderColor0: '#ef232a', |
|
|
opacity: function (params) { |
|
|
opacity: function (params) { |
|
|