Hello.
I want to customize the DoughnutSeries chart label and legend.
1. (Violet square) I succeeded in losing the text when the label value is 0.
However, I do not know how to delete it from the connector part.
2. (Orange square) I want to make the legend disappear for a value of 0, is it possible?
3. (Blue square) If you adjust the window size when aligning the pie chart to the left, the chart size is fixed.
However, if you set Stretch, the chart is shown in the center and the left and right margins increase. Is there a solution?
<*.xaml>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
Width
=
"auto"
/>
</
Grid.ColumnDefinitions
>
<
telerik:RadPieChart
Grid.Column
=
"0"
x:Name
=
"connectionChart"
>
<
telerik:RadPieChart.SmartLabelsStrategy
>
<
telerik:PieChartSmartLabelsStrategy
DisplayMode
=
"SpiderAlignedOutwards"
/>
</
telerik:RadPieChart.SmartLabelsStrategy
>
<
telerik:RadPieChart.Series
>
<
telerik:DoughnutSeries
ItemsSource
=
"{Binding ConnectionPieData}"
ClipToPlotArea
=
"False"
ValueBinding
=
"Value"
RadiusFactor
=
"0.7"
InnerRadiusFactor
=
"0.25"
ShowLabels
=
"True"
>
<
telerik:PieSeries.LabelDefinitions
>
<
telerik:ChartSeriesLabelDefinition
>
<
telerik:ChartSeriesLabelDefinition.Template
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Vertical"
>
<
TextBlock
Text
=
"{Binding Value, Converter={StaticResource ValueZeroConverter}}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:ChartSeriesLabelDefinition.Template
>
</
telerik:ChartSeriesLabelDefinition
>
</
telerik:PieSeries.LabelDefinitions
>
<
telerik:DoughnutSeries.SliceStyles
>
<
Style
TargetType
=
"Path"
>
<
Setter
Property
=
"Fill"
Value
=
"{Binding DataItem.Color}"
/>
</
Style
>
</
telerik:DoughnutSeries.SliceStyles
>
<
telerik:PieSeries.LegendSettings
>
<
telerik:DataPointLegendSettings
TitleBinding
=
"Title"
/>
</
telerik:PieSeries.LegendSettings
>
<
telerik:PieSeries.LabelConnectorsSettings
>
<
telerik:ChartSeriesLabelConnectorsSettings
/>
</
telerik:PieSeries.LabelConnectorsSettings
>
</
telerik:DoughnutSeries
>
</
telerik:RadPieChart.Series
>
</
telerik:RadPieChart
>
<
telerik:RadLegend
Grid.Column
=
"1"
Items
=
"{Binding ElementName=connectionChart, Path=LegendItems}"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Center"
/>
</
Grid
>
<*.xaml.cs ( Value Zero Converter) >
public class ValueZeroConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var slicesValue = double.Parse(value.ToString());
if (slicesValue == 0)
{
return string.Empty;
}
return string.Format("{0:N} %", slicesValue);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<*.model>
public class ReportGraphModel : ModelBase
{
public string Title { get; set; }
public double Value { get; set; }
public Brush Color { get; set; }
}
public class MainViewModel
{
...
ConnectionPieData = new ObservableCollection<
ReportGraphModel
>
{
new ReportGraphModel { Title = "Error", Value =error, Color = new SolidColorBrush(Colors.Red)},
new ReportGraphModel { Title = "Exception", Value =exception, Color = new SolidColorBrush(Colors.Violet)},
new ReportGraphModel { Title = "Normal", Value =normal, Color = new SolidColorBrush(Colors.Green)},
};
}
Thanks.