tradingview / charting-library-tutorial

This tutorial explains step by step how to connect your data to the Charting Library
MIT License
434 stars 317 forks source link

npx serve fail to load data correctly: Cannot read property 'time' of undefined #27

Open vozni4iy opened 3 years ago

vozni4iy commented 3 years ago

I tried to complete the tutorial. First of all, I need to change container to container_id in main.js to avoid an error. When I run npx serve, I see graph to be build, but no candles data to load. In a console I see an error Uncaught TypeError: Cannot read property 'time' of undefined at Socket. (streaming.js:45) at Socket.Emitter.emit (index.js:133) at Socket.onevent (socket.js:270) at Socket.onpacket (socket.js:228) at Manager. (index.js:21) at Manager.Emitter.emit (index.js:133) at Manager.ondecoded (manager.js:332) at Decoder. (index.js:21) at Decoder.Emitter.emit (index.js:134) at Decoder.add (index.js:246)

When I try to find out what is happening, I see that lastDailyBar is undefined, and those lines

if (firstDataRequest) {
            lastBarsCache.set(symbolInfo.full_name, {
                    ...bars[bars.length - 1],
                });
            }

didn't fire because firstDataRequest is undefined, too. So never get the first candle and all others are undefined

timocov commented 3 years ago

I need to change container to container_id in main.js to avoid an error.

That's because tutorial is adapted to be used with the latest unstable charting library version (which is v19 at the time), I think we need to mark it somewhere in the docs...

When I try to find out what is happening, I see that lastDailyBar is undefined, and those lines

Can you please try with the latest unstable version? I think it's related because we've changed the API in v19 for requesting bars.

vozni4iy commented 3 years ago

Thanks a lot! Seems working with unstable version. If I find other issues I will update.

vozni4iy commented 3 years ago

@timocov could you please help: I added 1H and 4H to supported_resolutions, but they didn't work. Resolutions are added to the dropdown, but when I click it dropped back to 1D. Day, week and month resolution works ok. Did I do something wrong or do I need external conditions (like paid plan) to enable resolutions less than 1D? I checked that in tradingview chart demo 1h interval could be enabled, but I can't do this in my project.

timocov commented 3 years ago

Day, week and month resolution works ok. Did I do something wrong or do I need external conditions (like paid plan) to enable resolutions less than 1D?

Your symbols should support such resolutions, see https://github.com/tradingview/charting_library/wiki/Symbology#supported_resolutions