Pie chart Percentages

Jul 11, 2009 at 6:21 PM

I'm using the new chart controls and I noticed that the percentages where off. When using the pie series I had multiple values but I was wondering how would you setup the chart to show the percentage of a certain amount.  For example.  If I wanted the chart to show the total of an amount and the different slices would show what the percentage of this item was of the total amount.  In other words If I have an amount of 100 and I have two items both worth 25 I should have 2 pieces that represent 50% of the total 100 amount.  I'm not sure exactly how this can be represented.

Jul 12, 2009 at 7:43 PM

Looks like I figured this one out myself.  Turns out all I had to do was calculate the percentage of the amounts and put them in an observablecollection that's bound to my chart.  Now I just need to know how to get my tooltip to show the independent value binding in the tooltip instead of the decimal values.

Coordinator
Jul 13, 2009 at 7:32 PM

I've blogged about modifying the default ToolTips here:

http://blogs.msdn.com/delay/archive/2009/05/19/chart-tweaking-made-easy-how-to-make-four-simple-color-tooltip-changes-with-silverlight-wpf-charting.aspx

Hope this helps!

Jul 13, 2009 at 8:46 PM

Thanks davidans,

I saw you're article some time ago but I can't get it to work.  I keep getting the following error which makes no sense so far.  Here my chart source.

                    <charting:Chart Title="BiWeekly Income/Expenses" Foreground="{DynamicResource FontColor}" FontFamily="Calibri"
                                    Background="{DynamicResource PanelGradientBrush}" LegendTitle="Legend" LegendStyle="{DynamicResource LegendStyle}">
                        <charting:PieSeries Name="PieSeriesChart" ItemsSource="{x:Static BLL:Checkbook.Expenses}" FontFamily="Calibri" StylePalette="ModifiedStylePalette" 
                               IndependentValueBinding="{Binding Type}" DependentValueBinding="{Binding PctOfIncome}">
                                            
                        </charting:PieSeries>

Checkbook.Expenses is an observablecollection
Here's the error.

System.Windows.Markup.XamlParseException occurred
  Message="'Collection`1' type does not have a public TypeConverter class.  Error at Line 239 Position 136."
  Source="PresentationFramework"
  LineNumber=239
  LinePosition=136
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
       at System.Windows.Markup.XamlTypeMapper.ThrowExceptionWithLine(String message, Exception innerException)
       at System.Windows.Markup.XamlTypeMapper.ThrowException(String id, String parameter)
       at System.Windows.Markup.XamlTypeMapper.GetTypeConverter(Type type)
       at System.Windows.Markup.XamlTypeMapper.GetPropertyConverter(Type propType, Object dpOrPiOrMi)
       at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId)
       at System.Windows.Markup.BamlRecordReader.ParseProperty(Object element, Type propertyType, String propertyName, Object dpOrPi, String attribValue, Int16 converterTypeId)
       at System.Windows.Markup.BamlRecordReader.ReadPropertyRecordBase(String attribValue, Int16 attributeId, Int16 converterTypeId)
       at System.Windows.Markup.BamlRecordReader.ReadPropertyRecord(BamlPropertyRecord bamlPropertyRecord)
       at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
       at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
       at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
       at System.Windows.Markup.TreeBuilder.Parse()
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at BudgetManager.MainWindow.InitializeComponent() in e:\Code\BudgetManager\BudgetManager\MainWindow.xaml:line 1
       at BudgetManager.MainWindow..ctor() in E:\Code\BudgetManager\BudgetManager\MainWindow.xaml.cs:line 49
  InnerException:

Coordinator
Jul 14, 2009 at 1:53 AM

I'm afraid I don't have enough context to say what might be going on here, though I agree with your opinion that the ItemsSource assignment seems to be to blame. One thing I'd suggest is trying the same syntax with an ItemsControl or ListBox. If it's broken there, then at least we know Charting's not causing the problem. If not, then maybe we can try to determine what about using that collection here is problematic...

Jul 14, 2009 at 1:43 PM
Edited Jul 14, 2009 at 5:06 PM

Found the problem.  My style code was incorrect.  I was passing the datapoint style instead of the datapoint controltemplate.  Works great now.  thanks for the help!