fix:修复标注问题

alphaFuthures
Lxy 4 weeks ago
parent 79502d00de
commit 8478210dd9

@ -1426,6 +1426,17 @@ function trRenderDetailKline(data, pair) {
} }
}); });
// 计算全局价格范围,用于确定标记偏移量
let globalLow = Infinity, globalHigh = -Infinity;
candles.forEach(c => {
const lo = parseFloat(c[3]);
const hi = parseFloat(c[4]);
if (lo < globalLow) globalLow = lo;
if (hi > globalHigh) globalHigh = hi;
});
const priceRange = globalHigh - globalLow;
const markerOffset = priceRange * 0.06; // 标记偏移量价格范围的6%
// 生成标记数据 // 生成标记数据
let minMarkerIdx = Infinity; let minMarkerIdx = Infinity;
let maxMarkerIdx = -Infinity; let maxMarkerIdx = -Infinity;
@ -1435,8 +1446,8 @@ function trRenderDetailKline(data, pair) {
const candle = candles[dateIdx]; const candle = candles[dateIdx];
const price = parseFloat(m.price); const price = parseFloat(m.price);
const low = parseFloat(candle[3]); const low = parseFloat(candle[3]);
const high = parseFloat(candle[4]); // 买标记放在K线下方远离柱体
const markerPrice = Math.max(low, Math.min(high, price)); const markerPrice = low - markerOffset;
buyMarkers.push({ buyMarkers.push({
name: `${m.offset || ''}`, name: `${m.offset || ''}`,
@ -1453,9 +1464,9 @@ function trRenderDetailKline(data, pair) {
const dateIdx = parseInt(idx); const dateIdx = parseInt(idx);
const candle = candles[dateIdx]; const candle = candles[dateIdx];
const price = parseFloat(m.price); const price = parseFloat(m.price);
const low = parseFloat(candle[3]);
const high = parseFloat(candle[4]); const high = parseFloat(candle[4]);
const markerPrice = Math.max(low, Math.min(high, price)); // 卖标记放在K线上方远离柱体
const markerPrice = high + markerOffset;
sellMarkers.push({ sellMarkers.push({
name: `${m.offset || ''}`, name: `${m.offset || ''}`,
@ -1564,7 +1575,7 @@ function trRenderDetailKline(data, pair) {
symbol: 'triangle', symbol: 'triangle',
symbolSize: 12, symbolSize: 12,
data: buyMarkers, data: buyMarkers,
label: { show: true, formatter: '{b}', fontSize: 10, color: '#10b981' }, label: { show: true, formatter: '{b}', fontSize: 10, color: '#10b981', position: 'bottom', distance: 5 },
}, },
}, },
{ {
@ -1581,7 +1592,7 @@ function trRenderDetailKline(data, pair) {
symbolSize: 12, symbolSize: 12,
symbolRotate: 180, symbolRotate: 180,
data: sellMarkers, data: sellMarkers,
label: { show: true, formatter: '{b}', fontSize: 10, color: '#ef4444' }, label: { show: true, formatter: '{b}', fontSize: 10, color: '#ef4444', position: 'top', distance: 5 },
}, },
}, },
{ {

Binary file not shown.
Loading…
Cancel
Save