Dynamic Visibility
The [ObservableObject]
, [ObservableProperty]
and [RelayCommand]
attributes come from the
CommunityToolkit.Mvvm package, you can read more about it
here.

View model
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.General.Visibility;
public partial class ViewModel : ObservableObject
{
public ISeries[] Series { get; set; } =
{
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 2, 5, 4, 3 },
IsVisible = true
},
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 6, 3, 2, 8 },
IsVisible = true
},
new ColumnSeries<double>
{
Values = new ObservableCollection<double> { 4, 2, 8, 7 },
IsVisible = true
}
};
[RelayCommand]
public void ToggleSeries0()
{
Series[0].IsVisible = !Series[0].IsVisible;
}
[RelayCommand]
public void ToggleSeries1()
{
Series[1].IsVisible = !Series[1].IsVisible;
}
[RelayCommand]
public void ToggleSeries2()
{
Series[2].IsVisible = !Series[2].IsVisible;
}
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinSample.General.Visibility.View"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Xamarin.Forms;assembly=LiveChartsCore.SkiaSharpView.XamarinForms"
xmlns:vms="clr-namespace:ViewModelsSamples.General.Visibility;assembly=ViewModelsSamples">
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Orientation="Horizontal">
<Button Margin="6" Command="{Binding ToggleSeries0Command}" Text="toggle 1" />
<Button Margin="6" Command="{Binding ToggleSeries1Command}" Text="toggle 2"/>
<Button Margin="6" Command="{Binding ToggleSeries2Command}" Text="toggle 3"/>
</StackLayout>
<lvc:CartesianChart Grid.Row="1" Series="{Binding Series}"></lvc:CartesianChart>
</Grid>
</ContentPage>