amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
353 stars 94 forks source link

How we get the first price in stock chart if the selected date is missing #1347

Closed ivannrs closed 7 months ago

ivannrs commented 8 months ago

Hey,

We are having the following issue using the latest 5.8.2 version of amchar ts [stock chart]. As expected the stock chart is meant to show mostly price, indexes or percentage changes between them. The chart works great, but in a case where a date range that is selected does not meet the prices availability.

Let's say we have a chart that shows the price changes in % of the cheese. But the cheese price is getting updated only in the working days and there is gaps in the holidays (we are using gapless chart btw). Ok and then we have a user who wants to see the prices from Sunday to Thursday. The new amchart version will consider as a first price the price in Monday, because the one in Sunday is missing, which is as correct as wrong. So we can see in such cases amcharts is looking for the next available price in the selected range. But if we get back to our real example and the user is actually buying cheese in Sunday there is no chance for him to pay the Monday's price, but will actually pay on the last available price - the one from Friday even its out of the range. Actually this is how amCharts 3 is working, we have observed that after a migration.

So the question is can we control this and make amcharts get as first price, the last price before the selected day. Would be great if this can be controlled somehow.

Environment amCharts version: 5.8.2 Browser and its version: Edge and Chrome Licensed version (the demo is of course not)

zeroin commented 8 months ago

We actually changed this quite recently, in v 5.8.0 - before, when calculating changes we used to take the first value which was drawn on the chart, and as we always want the series line to be drawn from currently visible item to the one which is out to the left, we used to include one extra data item. But as you said, it is also wrong in many cases.

I could make the old behavior as an alternative, but I guess you want something in the middle, like old behavior to work only if left zoom position happens on the day when there were no trades? This might be more complicated, I need some time to think, but could you confirm that it's actually what you are looking for? Or was it ok before 5.8.0?

ivannrs commented 8 months ago

Thanks for the reply @zeroin You are right I have just checked (can provide examples) and with 5.7.7 the first price was the first one available before the range start date. But why we do this in the cases where a price is available on the start date ?

I think your description is correct, the "previous price" logic should be only applied if there is no available price on the start date. I am also open for any kind of discussion if I can help with something. Thanks for your attention.

zeroin commented 8 months ago

I must say I don't see how to implement this. The thing is the axis in zoomToDates method converts date to the relative value and then forgets the date at all. So this would require fuzzy logic, saving the date and then forgetting it on some other zoom event. We are strongly against implementing such fuzzies. And you can still get the price and price change in legend or tooltip.

I imagine we could consider adding a setting which would tell to which side the date should snap if user calls zoomToDates on the date which is not there, this way, if user sets Sunday as "from", the chart could display Friday as first day, not Monday. Technically this is quite easy doable.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.