Dynamic Visibility

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

This web site wraps every sample using a ContentPage instance, but LiveCharts controls can be used inside any container.

sample image

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 x:Class="MauiSample.General.Visibility.View"
             xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Maui;assembly=LiveChartsCore.SkiaSharpView.Maui"
             xmlns:vms="clr-namespace:ViewModelsSamples.General.Visibility;assembly=ViewModelsSamples"
             >
    <ContentPage.BindingContext>
        <vms:ViewModel/>
    </ContentPage.BindingContext>
	<ContentPage.Content>
        <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.Content>
</ContentPage>

Articles you might also find useful: