tvjsx / trading-vue-js

💹 Hackable charting lib for traders. You can draw literally ANYTHING on top of candlestick charts. [Not Maintained]
https://tvjsx.github.io/trading-vue-demo/
MIT License
2.07k stars 629 forks source link

TypeError: Cannot read property 'interval_ms' of undefined #225

Open kempsteven opened 3 years ago

kempsteven commented 3 years ago

Description

I am trying to update the an overlays data, specifically "ROC" Overlay, i am using .merge to update the data, i use that to update chart.data this.chart.merge('chart.data', data), and it works perfectly, but when I update an Overlay like ROC I get the error TypeError: Cannot read property 'interval_ms' of undefined

Screenshot

image

Code (MVP)

const data = [[1617978600000, 2.38], [1618237800000, 2.31], [1618324200000, 1.58]]
this.chart.merge(`offchart.ROC5C.data`, data)

Console errors (if any)

image

Additional Info

(tvjs version, OS, browser, npm version...) "trading-vue-js": "^1.0.2"

I know the project's not being maintained, just hoping someone will help. thanks in advanced!

kempsteven commented 3 years ago

I've looked through the source code and it seems this.$refs.chart & this.tv.$refs.chart is undefined, not sure why tho

mjzarrin commented 3 years ago

I had a similar problem and the problem was about the frequency of calling update(). by adding some sleep between calls, the problem was solved.

Here is my working example .

async mounted() {
    for (const cdl of json.chart.data) {
      await new Promise((resolve) => setTimeout(resolve, 100))
      this.chart.update({ candle: cdl })
    }
  },
oneart-dev commented 3 years ago

Same problem. Do you find solution @kempsteven ?

oneart-dev commented 3 years ago

@mjzarrin where do you put this code? I have this problem when adding a new indicator, not on initial load.

Swoorup commented 3 years ago

Proper fix is to give the timeframe interval when you specify the datacube.

this.chart = new DataCube({
   chart: { tf: '1m '},

This is only an issue with ohlcv chart I guess?

oneart-dev commented 3 years ago

@Swoorup nope, the error not about missing TF but not able to get chart ref because its undefined. I found my problem. I was using v-if on TradingView component while loading chart data. Removing it fixed the issue.

So the main problem is tv extensions do not check for undefined refs.