I am using a XamDataChart to create a Waterfall graph that looks identical to this one.
To do this, I am using a RangeColumnSeries as well as a StackedColumnSeries. The RangeColumnSeries shows the individual range values (all columns but far right), and the StackedColumnSeries is showing those same values 'stacked' in the far right column. What I need to do is change the colors of individual columns in the RangeColumnSeries so that those colors line up with the colors used in the StackedColumnSeries individual StackedFragmentSeries items.
Any pointers on how to do this? I have tried using the LayoutUpdated event of the grid to use code to set the colors but I cannot seem to find the right properties in the object model to allow me to do so.
Attached a new image file. The one I linked to got cut off.
Hello Mike,
Thank you for your post. I have been looking into it and I created sample project for you with the functionality you want. Basically I created a Style for Rectangle, and handle its Loaded event, because the RangeSeries is created from Rectangles. In the handler I set different colors, which you can make match the ones in the Stacked Series.
Hope this helps you.
Thanks Stefan, that was very helpful. I had actually tried to go down that road previously without luck.
I am now able to get the colors to change on the individual bars using your example, however when I tab off the control and then back to it (it is in a XamDockManager) the bars 'forget' the color that was previous assigned to them.
The Rectangle_Loaded event actually fires about 57 times. Obviously there are other objects in the chart that are also derived from a Rectangle. I have tried resetting the counter to 0 after all rectangles have been processed so that the next time the event fires (on focus) that the rectangles are reset properly. This does not seem to work as the rectangles do not seem to fire the even in the same order as the first time into the control. If I just stop the logic in the event from firing after the initial load, then the bars seem to forget the color that was previously assigned.
Any ideas on how to deal with this?
I have attached an updated version of your project to demonstrate the issue. Navigate back and forth between the tabs and you will see the columns lose the color. The event fires for the rectangles in the new series I added. How do I limit it to just the series I care about?
I was able to answer my own question. By moving the style to the series that I care about...
<ig:RangeColumnSeries.Resources> <Style TargetType="{x:Type Rectangle}"> <EventSetter Event="Loaded" Handler="Rectangle_Loaded"/> </Style> </ig:RangeColumnSeries.Resources>
This means the event only fires for the rectangles I am concerned with. Also, I had to reset the counter to 0 in the Load event of the chart, so that when I switch tabs the colors are reset correctly.
Attached is the working solution.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.