240fbe7994
Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
(function () {
|
|
var el = document.getElementById('equity-curve-chart');
|
|
var raw = window.__EQUITY_CURVE__;
|
|
if (!el || !raw || !raw.length || !window.LightweightCharts) return;
|
|
|
|
function parseTime(s) {
|
|
if (!s) return null;
|
|
var t = String(s).trim().replace(' ', 'T');
|
|
if (t.length === 16) t += ':00';
|
|
var d = new Date(t);
|
|
if (isNaN(d.getTime())) return null;
|
|
return Math.floor(d.getTime() / 1000);
|
|
}
|
|
|
|
var data = [];
|
|
var lastTs = 0;
|
|
raw.forEach(function (p) {
|
|
var ts = parseTime(p.time);
|
|
if (ts == null) return;
|
|
if (ts <= lastTs) ts = lastTs + 1;
|
|
lastTs = ts;
|
|
data.push({ time: ts, value: Number(p.value) });
|
|
});
|
|
if (!data.length) {
|
|
el.innerHTML = '<p class="text-muted" style="padding:1rem">暂无资金曲线数据</p>';
|
|
return;
|
|
}
|
|
|
|
var c = {
|
|
bg: '#1a1d24',
|
|
text: '#9ca3af',
|
|
grid: '#2d3139',
|
|
line: '#6366f1',
|
|
};
|
|
var chart = LightweightCharts.createChart(el, {
|
|
width: el.clientWidth || 800,
|
|
height: 220,
|
|
layout: {
|
|
background: { type: 'solid', color: c.bg },
|
|
textColor: c.text,
|
|
fontSize: 11,
|
|
},
|
|
grid: {
|
|
vertLines: { color: c.grid },
|
|
horzLines: { color: c.grid },
|
|
},
|
|
rightPriceScale: { borderColor: c.grid },
|
|
timeScale: { borderColor: c.grid, timeVisible: true, secondsVisible: false },
|
|
});
|
|
var series = chart.addLineSeries({
|
|
color: c.line,
|
|
lineWidth: 2,
|
|
priceFormat: { type: 'price', precision: 2, minMove: 0.01 },
|
|
});
|
|
series.setData(data);
|
|
chart.timeScale().fitContent();
|
|
|
|
window.addEventListener('resize', function () {
|
|
chart.applyOptions({ width: el.clientWidth || 800 });
|
|
});
|
|
})();
|