tradingview / lightweight-charts

Performant financial charts built with HTML5 canvas
https://www.tradingview.com/lightweight-charts/
Apache License 2.0
8.85k stars 1.55k forks source link

How to hide the line series from null or zero to its value #1148

Closed jadeja-rajdeep closed 1 year ago

jadeja-rajdeep commented 1 year ago

Lightweight Charts Version: 3.8

Actual behavior: currently its display long line from 0 to the first available line series value. for example if i add 10 days ema on chart its display vertical line from bottom 0 to the 10 days ema first value.

Expected behavior:

it should be not display until the first value is provided or is there any kind of option available ?

Screenshots:

Screenshot 2022-08-15 at 18-54-56 Parwarvivah com - Admin Panel

SlicedSilver commented 1 year ago

Here is an example for a moving average chart: https://jsfiddle.net/TradingView/537kjtfg/

What you need to do within your code is remove the first 10 items from the EMA10 data set. You should only pass the points you want to plot to the setData() method.

For example: If you have a dataset of 20 points and you want to plot the EMA10 then you should expect the lengths of the data sets to be:

because the first 10 points of the EMA10 will be zero.

Simplest fix for your code would be something like this:

// instead of this:
// emaLineSeries.setData(ema10Data);

// do this:
emaLineSeries.setData(ema10Data.slice(10));

If you are unable to resolve your issue and still believe that there is a bug, then can you please reply with a jsFiddle (or other code sandbox) and we will reopen the issue.

jadeja-rajdeep commented 1 year ago

thank you very much for the help and guide.