CategoryAxis for CandleStickAndVolumeSeries

Samuel Guedon il y a 4 ans dans Documentation • mis à jour il y a 4 ans 1
Hi all,

I am making a candlestick chart to plot financial data and realised the datetime axis isn't the perfect fit for this as it will show gaps when the market are closed, while a proper graph should just join the data.

So I tried to do the trick using a category axis. It will be a bit harder as I will have to manage through code the format of the axis (going from a hh:mm to a dd MMM yyyy while dezooming) but this should be manageable.

My only problem now is that nothing is shown by the plotmodel. I guess this comes from the fact that the CandleStickAndVolumSeries refers X as double, while my axes is labelled. So how can I "explain" to the plot model that when he has 38016.69 for X it should make it appear on the 30 jan. 2004 label of my axis? Note that the CandleStickAndVolumSeries and the axis data follow the same order (indexes or equivalent).

I checked in the example but I couldn't find anything relevant.

Any help will be greatly appreciated
So after looking for a while, I had the great idea to look on Google (ok, it should have been the first idea :) ), and I found this documentation. Specifically, this part "The category axis is using the index of the label collection items as coordinates. If you have 5 categories in the Labels collection, the categories will be placed at coordinates 0 to 4. The range of the axis will be from -0.5 to 4.5 (excluding padding)."

So I added this little line of code :

private CandleStickAndVolumeSeries ModifyCandlestick(CandleStickAndVolumeSeries css)
for (int i = 0; i < css.Items.Count; i++)
css.Items[i].X = i;
return css;

I also keep the original record which is the one that is public even though it is not plotted to my PlotModel. It allows to the original date time coordinate.