Are negative values supported in Pie charts.

4 posts, 0 answers
  1. Dhruv
    Dhruv avatar
    15 posts
    Member since:
    Nov 2011

    Posted 03 Jun 2013 Link to this post

    Is there any way to plot negative values in Pie chart like we can do in Microsoft Excel.

    Below are snap shots of two charts having negative values one plotted using telerik chart and another using Excel.

  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 05 Jun 2013 Link to this post

    Hi Dhruv,

     Null, empty, negative, and zero values have no effect when calculating ratios. For this reason, these values are not shown on a pie chart. If you want to visually indicate these types of values on your chart, you'd better change the chart type to be something other than a pie chart.
    However if you insist on having this in a pie representation, use the absolute value of your data like this for example:

    pieSeries.ValueBinding = new GenericDataPointBinding<ChartData, decimal>() { ValueSelector = selector => Math.Abs(selector.Value) };

    Regards,
    Evgenia
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Dhruv
    Dhruv avatar
    15 posts
    Member since:
    Nov 2011

    Posted 06 Jun 2013 Link to this post

    I have already tried this option, It draws chart correctly but issue with approach is that when user hovers mouse over negative part of Pie chart it displays same absolute value in tool tip. This visual representation presents totally wrong picture to user which is not acceptable in our case. Can you please provide a way by which tooltip will still display a negative value and chart can be drawn using absolute value.
  5. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 11 Jun 2013 Link to this post

    Hi Dhruv,

     You can create a tooltip template where you bind to the business object's property that dictates the real slice value (in our case this is QuantitySold property) like this:

    <telerik:RadPieChart Grid.Row="2" Grid.Column="1" x:Name="RadPieChart" 
                                 Width="auto" Height="auto" >
                <chart:RadPieChart.Behaviors>
                    <telerik:ChartSelectionBehavior/>
                    <telerik:ChartTooltipBehavior/>
                </chart:RadPieChart.Behaviors>
                <telerik:RadPieChart.TooltipTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding DataItem.Name}"/>
                            <TextBlock Text="{Binding DataItem.QuantitySold}"/>
                        </StackPanel>
                    </DataTemplate>
                </telerik:RadPieChart.TooltipTemplate>
                <telerik:PieSeries SelectedPointOffset="0.6" x:Name="pieSeries">
                </telerik:PieSeries>
            </telerik:RadPieChart>

    And for the pie slice label, you may still show the absolute value of the QuantitySold property:

    ObservableCollection<Product> dataSource = new ObservableCollection<Product>()
                   {
                      new Product(){QuantitySold = -5 , Name = "slice1"},
                      new Product(){QuantitySold = 7 , Name = "slice2"},
                      new Product(){QuantitySold = 6 , Name = "slice3"},
                      new Product(){QuantitySold = 2 , Name = "slice4"},
                      new Product(){QuantitySold = -5 , Name = "slice5"},
                      new Product(){QuantitySold = -1 , Name = "slice6"},
                   };
                 
               pieSeries.ValueBinding = new GenericDataPointBinding<Product, double>() { ValueSelector = product => Math.Abs(product.QuantitySold) };
               pieSeries.ItemsSource = dataSource;

    Regards,
    Evgenia
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top