Sunday, February 19, 2012

In the pie chart,how to change the color for every piece?

I work with .NET 2005.

thank you ...

Brian Weckler has a post on using a custom chart palet:

First create a custom function to return a series color based on the group value. To be consistent, the function should use a hash table to map the same value to the same color:

Private colorPalette As String() = {"Green", "Blue", "Red", "Orange", "Aqua", "Teal", "Gold", "RoyalBlue", "#A59D93", "#B8341B", "#352F26", "#F1E7D6", "#E16C56", "#CFBA9B"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()

Public Function GetColor(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colorPalette(count Mod colorPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function

Create your chart and set the series value appropriately. Hide the legend in the chart properties dialog. Now create a table with with two columns and a single row grouped by the group expression used as the graph series. Set the color of the data point in the chart as well as the background color of the first column in the table to:

=Code.GetColor(Fields!Series.Value)

http://blogs.msdn.com/bwelcker/archive/2005/05/20/perfect-from-now-on-custom-chart-legends.aspx
|||thank you! I'll try it .|||Only problem with this solutions is that e.g. if you use this code on a bar chart the color of the bar doesn't matches the color in the chart legend. I wonder why. I've haven't if this is the same with the pie charts.

No comments:

Post a Comment