Colors for specific XamPieChart slices

Answered (Verified) This post has 1 verified answer | 14 Replies | 3 Followers Thread's RSS feed.

Francis
Points 5,124
Replied On: Wed, May 1 2013 11:20 AM Reply

Hello,

What is the best approach for assigning specific colors to specific XamPieChart slices?  For example, the "On Time" slice should always be green, and the "Late" slice should always be red.  If I simply declare a BrushCollection in XAML, then this works only if all possible data points are present, but if the "On Time" slice is empty, then the "Late" slice becomes green - wrong!.  I have to avoid this scenario...each slice should have one and only one color it can use.

Thanks for your help!

 

Francis

  • Post Points: 20

Verified Answer

Rob
Points 34,290
Infragistics Employee
Answered (Verified) Replied On: Thu, May 2 2013 2:32 PM Reply
Verified by Francis

Hi Francis,

I've uploaded a modified version of my previous sample.  If you open MainPage.xaml.cs and scroll to the bottom you will see a class called PieChartAttachedProperties where I'm storing the slices and using them in LayoutUpdated.  When you run the new sample there will be a button at the bottom of the page.  Click on that and you will see one of the pie slices change to black.  The slice changes as a result of binding updates from within the underlying data.

If you look in MainPage.xaml, inside the XamPieChart resources you will see a style. 

<Style TargetType="ig:Slice">
    <Setter Property="Background" Value="{Binding Path=Color}"/>
    <Setter Property="local:PieChartAttachedProperties.BindSliceBackground" Value="True"/>
</Style>

 

It sets the attached property to the Slice so when a Slice is generated the PieChartAttachedProperties class will store the slice to update the background accordingly.

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 40

All Replies

Rob
Points 34,290
Infragistics Employee
Replied On: Wed, May 1 2013 4:53 PM Reply

Hi Francis,

I looked into this a bit and unfortunately there is no easy way to do this.  The source code is specifically setting the background of the pie slice every time it sets the appearence.  This will override any bindings or styles that are set.  The only way I could get this to work was to handle the slice's LayoutUpdated event and everytime the layout updates I rebind the Slice to the data's Color property.  It's a very hacky way to do this but it's the only way I found that works given the current limitations.

I've determined this to be a new feature request and have sent your product idea directly to our product management team.  Our product team chooses new product ideas for development based on popular feedback from our customer base.  Infragistics continues to monitor application development for all of our products, so as trends appear in requested features, we can plan accordingly.

We value your input, and our philosophy is to enhance our toolset based on customer feedback.  If your feature is chosen for development, you will be notified at that time.  Your reference number for this product idea is PI13050002.

If you would like to follow up on your product idea at a later point, you may contact Developer Support management via email.  Please include the reference number of your product idea in the subject and body of your email message.  You can reach Developer Support management through the following email address:  dsmanager@infragistics.com

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 35
Francis
Points 5,124
Replied On: Thu, May 2 2013 11:23 AM Reply

Hi Rob,

Thanks for your investigation and submitting the PI request.

As for the workaround idea, which I'd like to implement, whether hackish or not...  If I handle LayoutUpdated in either your sample or in my application (using IG 12.2.20122.2053), sender is always null and e contains nothing.  Can you please confirm that I can use this event handler for this purpose?  Do you have any sample code doing the same?

Thanks again,
Francis

Francis

  • Post Points: 5
Francis
Points 5,124
Replied On: Thu, May 2 2013 11:30 AM Reply

PS - same behavior with 12.2.2012.2147

Francis

  • Post Points: 20
Rob
Points 34,290
Infragistics Employee
Replied On: Thu, May 2 2013 11:48 AM Reply

Hi Francis,

LayoutUpdated will not return the sender whether it's our controls or Microsoft's controls.  The last forum post on this thread describes it best: http://social.msdn.microsoft.com/Forums/en-US/silverlightcontrols/thread/10beaf7a-df0f-405b-a72a-3701c4760c83/

I used LayoutUpdated because it fires very frequently.  And because I used LayoutUpdated I needed to store the Slices once they were generated so I have access to them when the event fires.  That's why you see a for loop in my sample code: 

foreach (Slice slice in Slices)
{
    Binding b = new Binding("Color");
    slice.SetBinding(Slice.BackgroundProperty, b);
}

 

I'm storing all the generated slices in a List<T> and iterating over all of them.  Like I said it's a very hackish way to do this but given the limitations it was the only workaround I could come up with that worked.

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 20
Francis
Points 5,124
Replied On: Thu, May 2 2013 11:53 AM Reply

OK, thanks for the update.  I think I'm following, but the sample you sent may be the wrong one.  No loops are in the sample at all.  Did I get the right file from you?

Francis

  • Post Points: 5
Francis
Points 5,124
Replied On: Thu, May 2 2013 2:09 PM Reply

Still trying to figure out how to get the collection of Slices.  The XamPieChart doesn't expose them, as far as I can tell.  Sorry to be a nag, but I reeaaaaallllllly need to see a functioning sample. :)

Francis

  • Post Points: 20
Rob
Points 34,290
Infragistics Employee
Answered (Verified) Replied On: Thu, May 2 2013 2:32 PM Reply
Verified by Francis

Hi Francis,

I've uploaded a modified version of my previous sample.  If you open MainPage.xaml.cs and scroll to the bottom you will see a class called PieChartAttachedProperties where I'm storing the slices and using them in LayoutUpdated.  When you run the new sample there will be a button at the bottom of the page.  Click on that and you will see one of the pie slices change to black.  The slice changes as a result of binding updates from within the underlying data.

If you look in MainPage.xaml, inside the XamPieChart resources you will see a style. 

<Style TargetType="ig:Slice">
    <Setter Property="Background" Value="{Binding Path=Color}"/>
    <Setter Property="local:PieChartAttachedProperties.BindSliceBackground" Value="True"/>
</Style>

 

It sets the attached property to the Slice so when a Slice is generated the PieChartAttachedProperties class will store the slice to update the background accordingly.

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 40
Francis
Points 5,124
Replied On: Thu, May 2 2013 4:57 PM Reply

Awesome, thanks!  Your're right, it's a bit hacky, but works in my application.  I doubt I would have figured this one out on my own.

Francis

  • Post Points: 20
Rob
Points 34,290
Infragistics Employee
Replied On: Mon, May 13 2013 11:02 AM Reply

Hi Francis,

Let me know if you have any further questions on this.

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 20
Francis
Points 5,124
Replied On: Mon, May 13 2013 1:26 PM Reply

I'm all set, Rob, thanks again...

Francis

  • Post Points: 5
grubarec
Points 1,695
Replied On: Wed, Aug 14 2013 10:26 AM Reply

Hello Rob!

Do you have any updated information on the product idea PI13050002?

It would be great if the slices could be set to a specific color - e.g. by adding ColorMemberPath Property to the XamPieChart Definition.

Regards

 

 

  • Post Points: 20
Rob
Points 34,290
Infragistics Employee
Replied On: Mon, Sep 16 2013 11:55 AM Reply

Hi grubarec,

This product idea has not been implemented yet.  We've since moved to a new system for entering product ideas so I suggest that you head over to the new site and add this idea. http://ideas.infragistics.com/

There are many benefits to submitting a product idea:

- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you.  You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.

The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 20
dvsegmbh
Points 2,025
Replied On: Wed, May 14 2014 10:55 AM Reply

Hi, I have added this solution to my PieChart and Doughnut chart control, but it is not working for the FunnelCHart.

Can you suggest a solution for the funnel control slice background change?

  • Post Points: 20
Rob
Points 34,290
Infragistics Employee
Replied On: Thu, Jun 5 2014 9:23 AM Reply

Hi dvsegmbh,

I saw you were able to resolve your issue in a different thread.  I'm posting a link to that thread in case anyone else needs help with this. http://www.infragistics.com/community/forums/p/89637/442977.aspx

 

Sincerely,
Rob
Software Developer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 5
Page 1 of 1 (15 items) | RSS