This is a migrated thread and some comments may be shown as answers.

Are negative values supported in Pie charts.

3 Answers 223 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Dhruv
Top achievements
Rank 1
Dhruv asked on 03 Jun 2013, 10:00 AM

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.

3 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 05 Jun 2013, 02:55 PM
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.

0
Dhruv
Top achievements
Rank 1
answered on 06 Jun 2013, 08:44 AM
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.
0
Evgenia
Telerik team
answered on 11 Jun 2013, 07:39 AM
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.

Tags
Chart
Asked by
Dhruv
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Dhruv
Top achievements
Rank 1
Share this question
or