diff --git a/src/views/DataBrowser/TradingViewChart.tsx b/src/views/DataBrowser/TradingViewChart.tsx index 336d0756..90f37f53 100644 --- a/src/views/DataBrowser/TradingViewChart.tsx +++ b/src/views/DataBrowser/TradingViewChart.tsx @@ -120,17 +120,9 @@ const TradingViewChart: React.FC = ({ tickMarkMaxCharacterLength: 8, }, localization: { - locale: 'zh-CN', - // 自定义时间格式化,根据时间范围智能显示 - timeFormatter: (time) => { - const date = new Date(time); - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - - // 只显示年-月-日,简洁明了 - return `${year}-${month}-${day}`; - }, + locale: 'en-US', + // 使用 ISO 日期格式,强制显示 YYYY-MM-DD + dateFormat: 'dd MMM \'yy', // 这会被我们的自定义格式化器覆盖 }, handleScroll: { mouseWheel: true, @@ -143,6 +135,25 @@ const TradingViewChart: React.FC = ({ }, }); + // 设置时间轴的自定义格式化器(强制显示 YYYY-MM-DD) + chart.applyOptions({ + localization: { + timeFormatter: (time) => { + // time 可能是字符串 'YYYY-MM-DD' 或时间戳 + if (typeof time === 'string') { + return time; // 直接返回 YYYY-MM-DD 字符串 + } + + // 如果是时间戳,转换为 YYYY-MM-DD + const date = new Date(time * 1000); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; + }, + }, + }); + // 创建折线系列 (lightweight-charts 5.0 使用 addSeries 方法) // 第一个参数是 series 类本身(不是实例) const lineSeries = chart.addSeries(LineSeries, {