0

I'm using TradingView's Lightweight Charts to display a chart where the visible time range is set by a dropdown (ex: 1D, 1Y, etc). When the selected range as set by chart.timeScale().setVisibleRange() is wider than the timestamp range covered by the chart's data series, the chart sets the tine scale edges to match the data series rather than what was specified using setVisibleRange().

I would like the chart to always obey the range set by setVisibleRange(), even when it does not yet have data points to fill that entire range. How can I force it to do this, other than by setting empty/blank data points?

Here's an example where I set the left edge of the chart to 1 June 2018, but the chart only displays from 22 Sept. The left edge of the chart should obey setVisibleRange() and display empty space for the missing data points, without having to explicitly add empty data points:

https://jsfiddle.net/hgz9q3cy/

chart.timeScale().setVisibleRange({
  from: 1527811200, //Friday, 1 June 2018 00:00:00
  to: 1546300800, //Tuesday, 1 January 2019 00:00:00
});
  • Can you provide any example? – timocov Feb 05 '21 at 08:03
  • Added an example to the original post. – Thunderbelch Feb 14 '21 at 16:16
  • Thanks. `lightweight-charts` knows nothing about your data and how to extrapolate your data to the past/future, that's why the library uses search within a data for dates you've provided. You can use `setVisibleLogicalRange` if you know how much bars are between dates and/or can extrapolate it yourselves. – timocov Feb 14 '21 at 19:25
  • Thanks for the feedback, @timocov. I see now that it ignores the actual timestamps when determining where to draw each candle/bar and just draws all the samples spaced evenly. This can be a big problem if you have uneven time intervals, and is also the reason `timeScale().setVisibleRange()` with an empty sample for the start and end of the time window does not work in this case. Looks like the only option is to pad the data with enough empty samples when there isn't enough data to cover the desired time window. – Thunderbelch Feb 14 '21 at 23:22
  • @timocov - Would it be worth it to submit a feature request to make `lightweight-charts` honor timestamps when determining where to draw candles/bars (for data with uneven time intervals) and to honor the timestamps in `timeScale().setVisibleRange()` regardless of whether there are enough data points? Or is this such a niche requirement that it's unlikely to be implemented? – Thunderbelch Feb 14 '21 at 23:25
  • I don't think that we'll implement it in any future because 1) it's out of `lightweight-charts` scope and 2) could be implemented outside (via `setVisibleLogicalRange`). But who knows... – timocov Feb 15 '21 at 09:38

0 Answers0