Hi,
my chart is bound to a growing time series, but I would like to display a sliding-window of fixed size containing the last data. I use FinancialPriceSeries and CategoryDateTimeXAxis. How can I achieve this?
Thanks in advance,
Jerome
Jerome,
On some interval, you can add new points to a collection, and then check for points at the beginning of the collection that are too old and remove them. As long as your collection implements INotifyCollectionChanged the chart should be notified of these modifications and adjust accordingly. If you were using CategoryXAxis I would recommend just removing a fixed number of points from the beginning, and adding the same fixed number of points to the end on that interval, and that would keep the window sliding evenly. But the case is a bit more complex with CategoryDateTimeXAxis. Depending on your data you may need to do additional things to keep the window action smooth. It can end up being a bit compicated if you don't have the ability to set the minimum and maximum on the CategoryDateTimeXAxis. Fortunately, I believe we allow this in the latest service release for 10.3. Which version are you currently using?
-Graham
Hi Graham,
Thank you for the reply!
The sliding-window should run even if the oldest data are not removed (I want the chart to implement the sliding-window independently of the data that the chart observes). In any case, the way consisting of removing the last data doesn't work with CategoryDateTimeXAxis, as you already noticed, because the time-span being removed is not garanteed to be equal to the time-span being added.
So I intend to implement the sliding-window by setting on my own the min-max of the xaxis... Unfortunately, the min-max is not settable in the latest service release 10.3. It should be ok, if I set the WindowRect of the chart itself? Can you confirm? If you have a similar code sample, I would enjoy to have a look to the implementation...
Thanks,
Have you checked recently for the latest service release? I believe one was very recently released. If you look at the version on your assemblies, what does it say? I'm uncertain whether the min/max properties made it into that release, but my colleague Max thought they had.
Yes alternatively, you should be able to keep adjusting the WindowRect in order to move the view along your data and keep the timespan of the axis constant, but you will have to keep recalculating what to adjust the window to based on the whole range of the x axis.
Say the range between the first and the last points in your data is 4 months, if you wanted to display a window containing only the first month of the data then you would want to set your WindowRect to new Rect(0, 0, .25, 1) and if you wanted to see the second month of data you would have to set the WindowRect to Rect(.25, 0, .25, 1). As the range of dates in your data source changes, you will have to adjust the percentage of the axis shown (the width of the rectangle from 0 to 1, 1 being 100% shown), and the left of the rectangle which is the percantage down the axis that the window starts. You will have to dynamically adjust these percentages as the data changes and as the window "slides" to accomodate. One thing to concern yourself with is that if you leave this running for a long time, and dont remove any points from your collection ever, your performance and memory will start to take a hit.
Another option would be to build a proxy collection (and keep it updated) that only contains the points that are in the chart's current window. This keeps your memory and cpu more minimal, but you will either have to use the min/max features of the axis (when available), or load slightly more data than is necessary and keep the window range stable by updating the window as described above. Until the min/max properties are available, you can also emulate them by adding dummy values to the data set in question that have a Value double.NaN, they won't get displayed, but you can use them to control the minimum and maximum values of the CategoryDateTimeXAxis.
I don't believe we currently have a sample that attempts to build a sliding window using the WindowRect, has my above description assisted? Or would you like more guidance in this area?
Thank you very much for the information,
I actualized my version and now the CategoryDateTimeXAxis has MinimumValue and MaximumValue.Thank you for the tip.
I will try to avoid the data-proxy, because my data are limited in size (driven by mathematical analysis): I expect the xamdatachart to optimize the processing if it displays only a sub-part of the chart (your marketing argument: "[xamdatachart is] designed for handling high volumes of data ranging into the millions of data points, and into which updates can occur every few milliseconds") and my data are not so big: 7 series * 1000 points in 20 charts - slow refresh 1-3 times per minute.
For the display, I will implement the sliding window as you described using min/max.
I give you a feedback / ask you again if I need help,
Thank you,