我试图了解是否有可能在现有的(已经呈现的)图表上添加一个新的标记。
例如,在文档之后,我呈现了一个带有标记的蜡烛棒系列:
import { createChart, SeriesMarker } from "lightweight-charts";
const candleSeries = chart.addCandlestickSeries
// Prepare candleDataPoints and charMarkers with some logic ...
candleSeries.setMarkers(charMarkers);
candleSeries.setData(candleDataPoints);这很好,我用我想要的所有标记来渲染烛台系列,就在我需要的地方。
然后,我可以使用新的数据更新"candleSeries“,如IChartApi接口的文档所述:https://tradingview.github.io/lightweight-charts/docs/api/interfaces/IChartApi。
标记似乎是“附加”在candleSeries上的,我可以更新蜡烛,但不能更新标记。
这真的有可能吗?
提前感谢
发布于 2022-09-05 08:08:46
setMarkers方法不允许您更新(追加)到当前标记集,而是使用新值设置或替换所有标记。因此,为了附加到当前的标记集,您需要保持对这些标记的引用,并创建一个包含所有用于显示的标记的新数组。
const myMarkers = [{
time: data[data.length - 40].time,
position: 'aboveBar',
color: '#f68410',
shape: 'circle',
text: 'A'
}, /* more series markers... */
];
// ... some time later
// create another marker data point
const myNewMarker = {
time: data[data.length - 20].time,
position: 'aboveBar',
color: '#f68410',
shape: 'circle',
text: 'B'
};
// Create a new array with the existing markers and the new marker
// and use it within setMarkers
series.setMarkers([...myMarkers, myNewMarker]);因此,总结如下:
update方法。setMarkers方法时希望显示的所有标记。即将更新:从4.0版开始,ISeriesAPI上将有一个ISeriesAPI方法,它将返回该系列的当前标记数组。
https://stackoverflow.com/questions/73595128
复制相似问题