Question

I am new to wpf, I am using wpf toolkit to create pie chart. I have created pie chart using wpf toolkit but my problem is that I have to create Pie chart only with a particular color shade. Say for example green, then my pie chart should use shades of green only. Also this assignment of color to pie pieces should be done pro grammatically. Can anyone please advice how I go about it?

Was it helpful?

Solution

There isn't a simple answer to your question.
You can set the colors manually, or let the framework pick random ones for you.

What you could do, is have a method that takes as an argument the amount of series in your graph, and a color, and returns an array of colors of that color shade.

You'll have to look at how colors work (RGB) and figure out how you want to do that (keep in mind if you have heaps of series, this will not look good).

Have a look at this colorpicker page for a quick understanding of what you're looking for (in shades).

an example going from dark blue to white will have the following values:

#000000
#00001A
#000033
#00004C
#000066
#000080
#000099
#0000B2
#0000CC
#0000E6
#0000FF
#1919FF
#3333FF
#4D4DFF
#6666FF
#8080FF
#9999FF
#B2B2FF
#CCCCFF
#E6E6FF
#FFFFFF

and it shouldn't be hard to pick from that array 4 shades for example.

Then you'll have to manually (well, with a for loop, but still, in code) add them to your series.

OTHER TIPS

You can use below code in order to change the shades of the charts.

if you want to change from XAML then use this code:

<chartingToolkit:PieSeries x:Name="piecharts"   
        ItemsSource="{Binding DepartmentwiseGroupedEmployee}" 
        IndependentValuePath="DeptName" 
        DependentValuePath="DeptId">
  <chartingToolkit:PieSeries.Effect>
    <DropShadowEffect ShadowDepth="10" BlurRadius="14" Color="Green"/>
  </chartingToolkit:PieSeries.Effect>
</chartingToolkit:PieSeries>

or if you want to change from code then use below code:

var shadowEffect = new DropShadowEffect();
shadowEffect.Color = Colors.Green;
shadowEffect.ShadowDepth = 10;
shadowEffect.BlurRadius = 14;
piecharts.Effect = shadowEffect;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top