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 Collin,
The issue may be the type of chart you are using many of the chart require that the Series have the same data points in each series , therefore when your second collection changes it may not be displayed until the first collection also contains the same number. You can use a scatter line series which does not have this requirement when using the scatter line series when either series is updated the chart will be updated. This may eliminate your need to change the axis. See attached sample to let me know if this will meet your requirements. If this does fit your needs it appears that it would eliminate the need to add the legend in the code behind.
Hello Valerie,
Unfortunately some of our charts require line data along with range/range column data. Hmm. Is there any way to manually trigger the update, via an event or command of some sort that could be bound to? Or is that beyond the scope of the charts and am I stuck with whatever first series is bound being the one that defines when the axis is updated?
In my own testing I found that the chart is updated regardless of the number of points in a series (I had a sample where one series had 6 points to start with and one had 3), that the axis would only update based on the series it bound to, but the chart would still update each series when it had new data. If you're curious for the code that reproduces this I can zip and upload it; along with instructions on how to see the changing axis update behavior.
I did find my answer to the legend issue, by the way. I had to add one extra line of code in there to add the legend to the children of the XamDock in code. IE: (Chart.Parent as XamDock).Children.Add(legendObject); accomplished it.
Hello Colin,
If you have a sample that you could upload that would be great to better understand what you are doing and serve as a base to try and find a resolution.
Thanks,
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
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.
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.
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.