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,
The x:Name directive uniquely identifies XAML-defined elements in a XAML namescope the name is equivalent to the variable that holds an object reference or an instance as returned by a constructor so binding not a valid value for this property. You can bind to a different ItemsSource to change the data used by the axis or you can add the axis to the grid at runtime. Please let me know more about what you are trying to accomplish if you need further assistance.
Valerie
Okay, I'll see if I can explain differently to fully convey the scenario. There's two real issues, one is creating a legend in the code-behind that will display on the chart. I have the chart being placed inside a XamDock, then the legend is added to the chart in the code behind via:
var legend = new Legend {Content = "Common Legend", Margin = new Thickness(10) };
XamDock.SetEdge( legend, DockEdge.InsideRight );
Chart1.Legend = legend;
But I don't see any legend generated.
The other problem is with the axis. I can get the axis to show up, but there are multiple series in a chart and the series get updated asynchronously, but to the same points in the end. So for example; series1 and series2 may have 50 datapoints starting out, then series2 gets updated to 60 points, then series 1 gets updated to 60 points, but during the period between series 2 being updated and series 1 being updated the new data is not displayed. Axis is bound initially to series1, which I believe is the problem, but I cannot find a way in the code behind to bind the series to a series collection viewmodel, which holds the series objects.
Hopefully that explains better! If it's still confusing I'll try to figure out how to paste code so it shows up readable to explain better what I'm after.
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.
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