-1

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?

2 Answers2

0

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;
J R B
  • 2,069
  • 4
  • 17
  • 32
  • Thanks for timely reply but when I try to include I get error "The type chartingToolkit:PieSeries was not found. Are you missing any assembly reference". Am I missing any namespace? I am using following namespaces :- xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" – user2981965 Nov 12 '13 at 07:35
  • have you add reference of "System.Windows.Controls.DataVisualization.Toolkit" DLL in your project? – J R B Nov 12 '13 at 07:43
  • after add the reference of above DDL you have to add below tag in XAML file. xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" – J R B Nov 12 '13 at 07:45
  • Hi, the xaml code you have posted works but this gives a shadow effect to control to which I apply, it doesn't change colour of pie pieces. I want individual pie segments to consume shades of only one colour. Like if I apply GoGreen theme my pie chart should use only shades green colour, if its Aqua then shades of blue and so on... – user2981965 Nov 12 '13 at 09:11
0

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.

Noctis
  • 11,507
  • 3
  • 43
  • 82
  • Ok, So before each pie piece is rendered I would pass a colour from this array of chosen colour shade to that Pie segment. And yes the point is valid if I have a big data series, I would not be able to see effect of the shades. – user2981965 Nov 12 '13 at 10:55
  • Yep. When you create and add the series to the chart, you can define the color if my memory serves me right. Another option would be (assuming you know how many series you'll have), to have a limited set of theme colors with predefined shades of that color to use. – Noctis Nov 12 '13 at 10:58