Edmund Sulzanok
Edmund Sulzanok

Reputation: 1973

Updating lightweight-charts candlestick series results in Uncaught TypeError: Cannot read properties of undefined (reading 'year')

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'}]);

Upvotes: 4

Views: 3538

Answers (1)

Edmund Sulzanok
Edmund Sulzanok

Reputation: 1973

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.

Upvotes: 5

Related Questions