I have to display multiple charts where the X-axis is CategoryDateTimeAxis and the Y-Axis is NumericYAxis. The issue is that I don't know what the data will be since it's decided on run-time. I have successfully implemented the part where I can read the data from a file and display it on the chart.
The problem I am having is that I want to be able to display multiple line series at the same time. For example, the first chart contains some data points throughout the day of January 24th, and the second might contain some data points from January 25th. So initially I set the ItemsSource of the X-axis to the January 24th Data and also set the LineSeries to January 24th Data. This displays perfectly. Now, I need to display January 25th data on this chart too (by extending the chart's x-axis so 24th's data will be in the left half and 25th's data will be in the right half. These are the things I have tried:
1. Changing the X-axis ItemsSource to the 25th's Data and adding a new line series with 25th's data (after displaying 24th's line series). However, this then only displays 25th's line series and not 24th's.
2. I tried to concatenate data of both days together. So first I just display 24th's. Then when the user wants to see 25th's data as well, I concatenate the data for the X-axis ItemsSource but have two line series with each containing 24th's and 25th's data. This correctly displays the X-Axis to show the range from 24th to 25th but neither of the LineSeries is visible. (A possible solution maybe to edit the data for 24th to include 0s for the time range for 25th's and same for 25th but this is unfeasible for me since eventually I want this to work for multiple days and each day contains data points on the order of ~500,000).
It would be great if you could provide a solution for this. I am looking to see if this can work for not just 2 days but for multiple days on the same chart.
Thanks for all the help!
For the most part #2 is how you are supposed to set things up. Your CategoryDateTimeXAxis.ItemsSource needs to contain all data points that you intend to show, across all series. Then each series needs to bind to a collection of all the data points and for the points that series doesn't care about, set the value to double.NaN. This tells the chart to ignore those data points. So in short, each LineSeries needs to bind to a collection that contains points for both the 24th and 25th. The first series needs to set the 25th data points to double.NaN and the second series needs to set the 24th data points to double.NaN. Take a look at my attached sample.
Let me know if you have any questions.
Thanks for the answer. Your example makes sense. However, in my case, each day may contain approximately 500,000 data points so it seems rather inefficient to have to create about 500,000 extra data points for each day (and it could be for multiple days). Is there no other way to do it?
One other approach I was thinking of was to create line series with new Axis for each series. But set the range for all of them to be the same and only make one of them visible. Do you think this would work?
Actually yeah I think that will work. If you were using a CategoryXAxis it wouldn't because all series would be rendered from the left hand side no matter what but CategoryDateTimeXAxis is based on a date range and I believe it can position data points within the axis based on their dates. I hadn't even thought of doing it that way, very nice idea. I attached a sample that shows your idea will work.
With 500,000 data points per day though, make sure you disable markers on the LineSeries. With that many points, enabling markers will impact performance of the WPF framework.
Thanks for the sample. It works well.
Do you have other ideas on how to make the performance better since displaying even two or three series where each contain about 500,000 points is slowing it down considerably? There is a good amount of lag especially in zooming in and out. The only thing I am using for each line series is a tooltip but no markers. There is a data point tracker though. Any ideas to speed this up would be greatly appreciated!
Are you working with testing data right now? And if so, is it purely random? The chart doesn't handle purely random data very well because there are no optimizations it can make to the geometry shape when the points are completely random. Also, the more series that you include the more elements get added to the visual tree which can affect WPF performance. Our LineSeries is drawn using a single Path object which contains all the geometry for the shape but if you add a bunch of LineSeries, you'll end up with a bunch of Path objects as well, each with their own complex geometry that WPF has to render.
There's also a hit in performance for using a CategoryDateTimeXAxis. There are extra calculations that this axis type needs to make in order to correctly position your data where as a normal CategoryXAxis doesn't. Using a CategoryXAxis will effectively ignore the X axis positioning calculations. The CategoryDateTimeXAxis cannot ignore this axis and I think it even tries to sort your data in order to make sure everything is correct for when trying to position points. This sorting logic is probably what is causing a good chunk of the performance issue you see. Unfortunately there's nothing you can do about that currently as we don't have a way to disable this sort, even if your data is already sorted. The recommendation would be to use a CategoryXAxis, but then you would probably run into the original issue again.
Take a look at our documentation on chart performance for more info:http://help.infragistics.com/doc/WPF/2015.2/CLR4.0/?page=DataChart_Chart_Performance.html