c# - Silverlight Toolkit ; Pie Chart Avoiding Some Colors -


we need create chart service types. types can added dynamically , don't have proper color definition each of them.

so using telerik silverlight radchart , fine until client came trick requirement. shouldn't show 2 colors in grid: red , green.

there way avoid red , green palette of colors , still able render chart random colors?

a solution toolkit charts generate colors in c# code , rewrite pie data point template. way have found article explaining same approach telerik charts: binding color of series items

so if want eliminate 2 colors, set other colors chartitemmodel.color property. c# code this:

public class chartitemmodel {     public string title { get; set; }      public double value { get; set; }      public brush color { get; set; } }  var chartitems = new []  {      new chartitem { title = "item1", value = 25, color = (brush)resources["bluebrush"] },      new chartitem { title = "item2", value = 75, color = (brush)resources["yellowbrush"] }     // other items, color property of doesn't have red or green brush }; // binding 

and piedatapoint template copied built-in 1 , changed adding binding brush (fill="{binding color}"):

<charting:pieseries.datapointstyle>     <style targettype="charting:piedatapoint">         <setter property="template">             <setter.value>                 <controltemplate targettype="charting:piedatapoint">                     <grid x:name="root" opacity="0">                         <visualstatemanager.visualstategroups>                             <visualstategroup x:name="commonstates">                                 <visualstategroup.transitions>                                     <visualtransition generatedduration="0:0:0.1" />                                 </visualstategroup.transitions>                                 <visualstate x:name="normal" />                                 <visualstate x:name="mouseover">                                     <storyboard>                                         <doubleanimation storyboard.targetname="mouseoverhighlight" storyboard.targetproperty="opacity" to="0.6" duration="0" />                                     </storyboard>                                 </visualstate>                             </visualstategroup>                             <visualstategroup x:name="selectionstates">                                 <visualstategroup.transitions>                                     <visualtransition generatedduration="0:0:0.1" />                                 </visualstategroup.transitions>                                 <visualstate x:name="unselected" />                                 <visualstate x:name="selected">                                     <storyboard>                                         <doubleanimation storyboard.targetname="selectionhighlight" storyboard.targetproperty="opacity" to="0.6" duration="0" />                                     </storyboard>                                 </visualstate>                             </visualstategroup>                             <visualstategroup x:name="revealstates">                                 <visualstategroup.transitions>                                     <visualtransition generatedduration="0:0:0.5" />                                 </visualstategroup.transitions>                                 <visualstate x:name="shown">                                     <storyboard>                                         <doubleanimation storyboard.targetname="root" storyboard.targetproperty="opacity" to="1" duration="0" />                                     </storyboard>                                 </visualstate>                                 <visualstate x:name="hidden">                                     <storyboard>                                         <doubleanimation storyboard.targetname="root" storyboard.targetproperty="opacity" to="0" duration="0" />                                     </storyboard>                                 </visualstate>                             </visualstategroup>                         </visualstatemanager.visualstategroups>                         <path x:name="slice" data="{templatebinding geometry}" fill="{binding color}" stroke="{templatebinding borderbrush}" strokemiterlimit="1">                             <tooltipservice.tooltip>                                 <stackpanel>                                     <contentcontrol content="{templatebinding formatteddependentvalue}" />                                     <contentcontrol content="{templatebinding formattedratio}" />                                 </stackpanel>                             </tooltipservice.tooltip>                         </path>                         <path x:name="selectionhighlight" data="{templatebinding geometryselection}" fill="red" strokemiterlimit="1" ishittestvisible="false" opacity="0" />                         <path x:name="mouseoverhighlight" data="{templatebinding geometryhighlight}" fill="white" strokemiterlimit="1" ishittestvisible="false" opacity="0" />                     </grid>                 </controltemplate>             </setter.value>         </setter>     </style> </charting:pieseries.datapointstyle> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -