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

Hide label with value 0 in RadPieChart

2 Answers 57 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 14 Aug 2018, 11:50 AM

Hello all, 

How hide label with value 0 in a RadPieChart ?

Here is my current code (and the result is in attachment) :

<telerik:RadPieChart x:Name="PieChart" Grid.Row="0">
    <telerik:RadPieChart.Behaviors>
        <telerik:ChartTooltipBehavior />
    </telerik:RadPieChart.Behaviors>
    <telerik:RadPieChart.Series>
        <telerik:DoughnutSeries ItemsSource="{Binding GraphItems}" ValueBinding="Value" ShowLabels="True">
            <telerik:DoughnutSeries.TooltipTemplate>
                <DataTemplate>
                    <Border Background="Black" Padding="5" TextElement.Foreground="White">
                        <StackPanel>
                            <TextBlock Text="{Binding DataItem.Label}" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Value}" FontWeight="Bold" />
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </telerik:DoughnutSeries.TooltipTemplate>
            <telerik:DoughnutSeries.SliceStyles>
                <Style TargetType="Path">
                    <Setter Property="Fill" Value="{Binding DataItem.Color}" />
                </Style>
            </telerik:DoughnutSeries.SliceStyles>
            <telerik:DoughnutSeries.LabelDefinitions>
                <telerik:ChartSeriesLabelDefinition Margin="9 0 0 0" DefaultVisualStyle="{StaticResource LabelStyle}">
                    <telerik:ChartSeriesLabelDefinition.Binding>
                        <telerik:PropertyNameDataPointBinding PropertyName="Value" />
                    </telerik:ChartSeriesLabelDefinition.Binding>
                </telerik:ChartSeriesLabelDefinition>
            </telerik:DoughnutSeries.LabelDefinitions>
        </telerik:DoughnutSeries>
    </telerik:RadPieChart.Series>
</telerik:RadPieChart>

 

Thx,

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 15 Aug 2018, 10:12 AM
Hello Julien,

To achieve your requirement you can define a DataTemplate for the label and use an IValueConverter to return an empty label if the value is zero. For example:
public class ValueToLabelConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (the value is 0)
        {
            return string.Empty;
        }
        return value;
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

<telerik:ChartSeriesLabelDefinition.Template>
    <DataTemplate>
        <TextBlock Text="{Binding Label, Converter={StaticResource ValueToLabelConverter}}" />
    </DataTemplate>
</telerik:ChartSeriesLabelDefinition.Template>

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Julien
Top achievements
Rank 1
answered on 16 Aug 2018, 09:51 AM

Hi,

It works perfectly. I used a converter that changes the visibility.

Thx,

Tags
ChartView
Asked by
Julien
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Julien
Top achievements
Rank 1
Share this question
or