In our application a varying number of charts can be created based upon user configuration. The axis information is also user configurable, and this is where the problem comes in.
In creating the axes for the chart, can the name be bound to a property on our axis viewmodel? (I do not think so as my experimentation with x:Name={Binding Path=ViewModel.Name} so far) or is there some way to use RelativeSource binding to locate the axis information? Can this be done for the legend as well? Thank you!
Hello Valerie,
So basically I'll have to massage the data to get this to behave. This is unfortunate, but understandable. That answers my questions, thank you very much for your assistance.
Hello Colin,
When you add series using a category X axis the chart does not plot the series considering both the X and Y data coordinates, instead it plots each data point sequentially in the next slot on the X axis. So all series bound to the grid should maintain the same progression of data points. If a series is missing a data point it should be added with either a “null” value and/or using points that have interpolated values between the last point and the next point so the series progresses at the correct point on the X axis. Please see the modified sample which adds unknown values as place holders for missing points on the X axis and run with UnknownValuePlotting in the series defintion commented out and uncommented to see the behavior best.
Let me know if you have any questions.
Valerie
That's useful and works great for series which have the same spacing. Thank you.
Now what can be done in the case where there is a series with a point for every X points on the other series? Say series 1 has 1 point on every multiple of 5 in series 2. In my testing with your updated code on this; the axis far outpaces the series and the points are not tracked as I would assume; which is that if a series point's X appears at 15 (with no points at 14 or 13) it would put a point at X line 15, and there wouldn't be any points at 13 and 14. What I'm seeing is that the axis gets a new value for that, but it doesn't add in to the right points.
Is this possible? Please see updated sample.
Hello Collin,
The data points are plotted on the grid with a one-to one correspondence to the Labels on the Category X axis; they are not matched by their X values. When you bind the category X axis to the second collection there is no corresponding slot on the X Axis to put the new values from the first series until the second series catches up.
If both of your sequences always contain the same X values added in order (i.e., 0,1,2,3…) but the only variable is which series progresses faster you can create a third Observable Collection which you add the new data points to provided that the X value does not already exist in the collection. In this way the category X axis will expand based on either series increasing first. Please see revised sample.
Let me know if this meets your needs.
Valerie, attached is a sample project with instructions in the comment of MainWindow.xaml.cs as to repeat the behavior I describe. Hopefully I made it clear enough!
-Collin