更新轻量级图表烛台系列会导致未捕获的类型错误:无法读取未定义的属性(读取“年份”)

发布于 2025-01-19 03:50:41 字数 1114 浏览 0 评论 0原文

在烛台系列上运行更新时,我收到Uncaught TypeError:无法读取未定义的属性(读取“年份”)。数据的准备方式与 setData 相同,如下所示:[{time: 1649068320, open: '0.15721000', high: '0.15776000', low: '0.15710000', close : '0.15760000'}]

我在这里缺少什么?

我尝试使用与 setData 相同的数据进行更新,但出现了相同的错误。

还尝试以这种方式准备数据: var time = moment(item.openTime); time = { 年:time.year(),月:time.month(),日:time.day(),小时:time.hour(),分钟:time.min(),秒:time.second() , } 和 var time = new Date(item.openTime)

重现的最少步骤

import { createChart } from 'lightweight-charts';
var container = document.getElementById('price-chart');
const chart = createChart(container, {height:300});
chart.applyOptions({
    timeScale: {
        visible: true,
        timeVisible: true,
    },
});
const candlestick = chart.addCandlestickSeries();
candlestick.setData([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);
candlestick.update([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);

When running update on candlestick series I'm getting Uncaught TypeError: Cannot read properties of undefined (reading 'year'). Data is prepared the same way it was for setData and look like this: [{time: 1649068320, open: '0.15721000', high: '0.15776000', low: '0.15710000', close: '0.15760000'}].

What am I missing here?

I tried to update with same data as was used with setData and got same error.

Also tried to prepare data this way:
var time = moment(item.openTime); time = { year: time.year(), month: time.month(), day: time.day(), hour: time.hour(), minute: time.minute(), second: time.second(), } and var time = new Date(item.openTime)

Minimum steps to reproduce

import { createChart } from 'lightweight-charts';
var container = document.getElementById('price-chart');
const chart = createChart(container, {height:300});
chart.applyOptions({
    timeScale: {
        visible: true,
        timeVisible: true,
    },
});
const candlestick = chart.addCandlestickSeries();
candlestick.setData([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);
candlestick.update([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2025-01-26 03:50:41

更新采用单个对象。因此,还

candlestick.update([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);

应该是

candlestick.update({time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'});

  • 您不能在过去的数据上使用Update。因此,当向后滚动时,您需要使用setData
  • 在设置数据时,数组必须按时间顺序排列,否则您将获得undfult的错误:值是null

update takes single object. so instead of

candlestick.update([{time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'}]);

it should be

candlestick.update({time: 1649102700, open: '3.39110000', high: '3.39130000', low: '3.38610000', close: '3.38670000'});

Also:

  • You cannot use update on past data. So when scrolling backwards, you need to use setData
  • when setting data, array must be in chronological order or you will get Uncaught Error: Value is null.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文