如何在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
相关产品推荐
相关产品推荐

