Select to view content in your preferred language

Silverlight pie chart sizing

1854
5
06-04-2011 12:12 PM
JoeWhite
Emerging Contributor
Hi,
I'm relatively new to Silverlight and I'm trying to adapt the pie chart sample.  Basically what I want is to be able to bind the scale of the chart to a dependency property in the .cs file.  Unfortunately, I'm unable to get access to either the RenderTransform or the ScaleTransform.  I've tried a couple of different ways to get access to it, including using IValueConverter and TemplateBinding.  Obviously there is something I'm missing, but I don't know what it is.  A few pointers would be very helpful, if possible.

Thanks in advance,

Joe White
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
I'm relatively new to Silverlight and I'm trying to adapt the pie chart sample. Basically what I want is to be able to bind the scale of the chart to a dependency property in the .cs file. Unfortunately, I'm unable to get access to either the RenderTransform or the ScaleTransform.


A scale transform is already defined on the pie marker symbol (for the visualstate manager):
<Canvas.RenderTransform>
 <ScaleTransform ScaleX="0.6" ScaleY="0.6" />
</Canvas.RenderTransform>


If you add a 'Scale' dependency property in PieMarkerSymbol.cs, then you can use it in XAML this way:

<Canvas.RenderTransform>
 <ScaleTransform ScaleX="{Binding Symbol.Scale}" ScaleY="{Binding Symbol.Scale}" />
</Canvas.RenderTransform>

Note : don't forget to adapt or remove the visualstatemanager as well.
0 Kudos
JoeWhite
Emerging Contributor
Thanks for the reply.  I've tried adding the bindings to the dependency property in the .cs file, but it wouldn't bind.  I must have missed the changes to the visualStateManager.  I'll give that a try and let you know.

Thanks

Joe
0 Kudos
JoeWhite
Emerging Contributor
Hi, Domonique,
Oviously I'm still screwing this up.  I've disabled the animations on hover, just to make sure they don't interefere, and setting a binding for a ScaleFactor dependency property in the class. When I do this, it acts like the binding can't be found, and each symbol is being scaled to 1.0. 
The scale code is below:

Graphic graphic = new Graphic()
int importValue = random.Next(1000000000);
double scaleFactor = (double)importValue / 1000000000; //median value
graphic.Attributes["IMPORT"] = importValue;
graphic.Attributes["EXPORT"] = random.Next(1000000000);
pieChartMarkerSymbol.ScaleFactor = scaleFactor;
graphic.Symbol = pieChartMarkerSymbol;
graphicsLayer.Graphics.Add(graphic);

One additional question:  Does this set the scale on all of the PieChartMarkerSymbols in a given Layer?  If so, that's not exactly what I'm looking for.  I would like to set a different scale for each PieChartMarkerSymbol.

In any case, thanks for the replies.  If you have any other pointers, I'd really appreciate them.

Thanks

Joe
0 Kudos
DominiqueBroux
Esri Frequent Contributor
pieChartMarkerSymbol.ScaleFactor = scaleFactor;


Where is coming pieChartMarkerSymbol from? 

If it's an unique instance, that can't work because all graphics are sharing the same symbol and so the same scaleFactor (the last one you initialized).

There are a few options to avoid this issue:
     - create a symbol by graphic (not recommended for performances)
     - create a few symbols with various scales and use them in a classBreakRenderer that you affect to your layer
     - store the scale in an attribute of your graphics (e.g. graphic.Attributes["SCALE"] = scaleFactor;) and change your symbol in order to bind to this attribute (e.g. <ScaleTransform ScaleX="{Binding Attributes[SCALE]}" ScaleY="{Binding Attributes[SCALE]}" />)

Note : In the latest case you don't need anymore the ScaleFactor dependency property.



0 Kudos
JoeWhite
Emerging Contributor
Dominique,
I used your third suggestion and modified the animation to match.  It worked perfectly!  I really appreciate all of your help.

Joe
0 Kudos