You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在TradingView Lightweight Charts中移除非交易时段?

移除Lightweight Charts中的非交易时段

Lightweight Charts 有现成的配置项可以隐藏非交易时段的空白,你只需要在 timeScale 的配置中添加 nonTradingTimeVisible: false 即可。

把你的图表配置代码修改成这样:

const chart = createChart(chartContainerRef.current, {
  crosshair: {
    mode: 0, // CrosshairMode.Normal
  },
  layout: {
    background: { type: ColorType.Solid, color: colors.backgroundColor },
    textColor: colors.textColor,
  },
  timeScale: {
    borderColor: "#fff000",
    visible: true,
    timeVisible: true,
    secondsVisible: true,
    nonTradingTimeVisible: false, // 新增此行,隐藏非交易时段空白
  },
  width: chartContainerRef.current.clientWidth,
  height: 500,
});
chart.timeScale().fitContent();

这个参数会让图表自动压缩非交易时段的空白区域,只展示有数据的交易时段,完全适配你5分钟级别的数据需求。如果之后需要自定义非交易时段规则(比如特定节假日、自定义休市时间),还可以结合 timeScale().setVisibleRange() 或者预处理数据过滤非交易条目,但对新手来说,上面的配置已经能解决问题。

内容的提问来源于stack exchange,提问作者Joshua Ochia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 08:43:13