Search code examples
javascripthtmltradingview-apilightweight-charts

(Tradingview lightweight) Crooked line graph when switch data arrays


I'am trying to display 2 different graphs on the same canvas upon click of an onclick function.

My page defaults to the 1 Min line graph and a volume(histogram) graph at the bottom. The lightweight charts can draw the line and volume graphs without any issue.

When I switch my graph to a 3 Min graph, the volume graph gets displayed without any issue but my line graph gets crooked. As shown in the attached image.

Before I draw the 3 Min graph I would remove both the 1 Min line and volume serieses, after that I would create the 3 Min line and volume serieses and add in the 3 Min line and volume data arrays.

How can I solve this issue?

Crooked Line graph


Solution

  • In my original code, I had four serieses:

    • 1 min candles
    • 1 min volume
    • 3 min line
    • 3 min volume

    I modified my code to have only 3 serieses:

    • candle
    • volume
    • line

    And change the datasets accordingly using the series.setData method.

    The graph now shows the data properly.