Skip to content

Commit a70536b

Browse files
Updated README.md
1 parent 8cb1cf4 commit a70536b

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ This article will explain the step to hide or collapse specific data labels in a
88

99
**[XAML]**
1010
```
11-
<DataTemplate x:Key="labelTemplate">
12-
<HorizontalStackLayout HorizontalOptions="Center">
13-
<Label Text="{Binding Item.Value}" VerticalOptions="Center"/>
14-
<Label Text="%" VerticalOptions="Center"/>
15-
<Image Source="greenarrow.png" HeightRequest="15" WidthRequest="15" />
16-
</HorizontalStackLayout>
17-
</DataTemplate>
11+
<DataTemplate x:Key="labelTemplate">
12+
<HorizontalStackLayout HorizontalOptions="Center">
13+
<Image Source="greenarrow.png" HeightRequest="15" WidthRequest="15" />
14+
<Label Text="{Binding Item.Value}" VerticalOptions="Center"/>
15+
<Label Text="%" VerticalOptions="Center"/>
16+
</HorizontalStackLayout>
17+
</DataTemplate>
1818
```
1919
**Step 2:** Create a value to visibility converter to control the visibility of the data label based on the Y-value. For example, in the following converter, we have collapsed the visibility of the data label for values less than 50.
2020

@@ -24,10 +24,9 @@ This article will explain the step to hide or collapse specific data labels in a
2424
{
2525
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
2626
{
27-
if (!(value is double))
27+
if (!(value is double labelValue))
2828
return null;
2929
30-
var labelValue = (double)value;
3130
if (labelValue < 50)
3231
return false;
3332
return true;
@@ -46,15 +45,12 @@ This article will explain the step to hide or collapse specific data labels in a
4645
<chart:SfCartesianChart.Resources>
4746
<model:VisibilityConverter x:Key="visibilityConverter"/>
4847
<DataTemplate x:Key="labelTemplate">
49-
<VerticalStackLayout IsVisible="{Binding Item.Value, Converter={StaticResource visibilityConverter}}" Spacing="5" WidthRequest="100">
50-
<HorizontalStackLayout HorizontalOptions="Center" IsVisible="{Binding Item.Value}">
51-
<Label Text="{Binding Item.Value}" VerticalOptions="Center"/>
52-
<Label Text="%" VerticalOptions="Center"/>
53-
<Image Source="greenarrow.png" HeightRequest="15" WidthRequest="15" />
54-
</HorizontalStackLayout>
55-
</VerticalStackLayout>
48+
<HorizontalStackLayout HorizontalOptions="Center" IsVisible="{Binding Item.Value, Converter={StaticResource visibilityConverter}}">
49+
<Image Source="greenarrow.png" HeightRequest="15" WidthRequest="15" />
50+
<Label Text="{Binding Item.Value}" VerticalOptions="Center"/>
51+
<Label Text="%" VerticalOptions="Center"/>
52+
</HorizontalStackLayout>
5653
</DataTemplate>
57-
5854
</chart:SfCartesianChart.Resources>
5955
```
6056
**Step 4:** Set the defined DataTemplate to the [LabelTemplate](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_LabelTemplate) property of [ColumnSeries](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ColumnSeries.html).
@@ -64,7 +60,7 @@ This article will explain the step to hide or collapse specific data labels in a
6460
<chart:SfCartesianChart x:Name="Chart">
6561
. . .
6662
<chart:SfCartesianChart.Series>
67-
<chart:ColumnSeries ItemsSource="{Binding ElectricityProductionData}"
63+
<chart:ColumnSeries ItemsSource="{Binding Data}"
6864
LabelTemplate="{StaticResource labelTemplate}"
6965
ShowDataLabels="True"
7066
XBindingPath="Year"
@@ -78,4 +74,4 @@ This article will explain the step to hide or collapse specific data labels in a
7874
</chart:SfCartesianChart>
7975
```
8076
**Output**
81-
![collapse_the_visibility_of_specific_data_label.png](https://support.syncfusion.com/kb/agent/attachment/article/15889/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjIxODEzIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.K6J1qSq6NfGaIUqf9C-P6RbvLE-nRspU5QqfWg49jSc)
77+
![collapse_the_visibility_of_specific_data_label.png](https://support.syncfusion.com/kb/agent/attachment/article/15889/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjIyMTg5Iiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.cBwXqvUHvRWwf42SCvO5NwWNU1mr5LcsR4kVAR375v8)

0 commit comments

Comments
 (0)