Dynamic Visibility

This sample uses C# 12 features, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.

sample image

View model

using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace ViewModelsSamples.General.Visibility;

public partial class ViewModel
{
    public ISeries[] Series { get; set; } = [
        new ColumnSeries<double>
        {
            Values = [2, 5, 4, 3],
            IsVisible = true
        },
        new ColumnSeries<double>
        {
            Values = [6, 3, 2, 8],
            IsVisible = true
        },
        new ColumnSeries<double>
        {
            Values = [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

<UserControl x:Class="AvaloniaSample.General.Visibility.View"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
             xmlns:vms="using:ViewModelsSamples.General.Visibility">
  <UserControl.DataContext>
    <vms:ViewModel/>
  </UserControl.DataContext>
  <Grid>
      <Grid.RowDefinitions>
          <RowDefinition Height="30"/>
          <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <StackPanel Grid.Row="0" Orientation="Horizontal">
          <Button Command="{Binding ToggleSeries0Command}" Margin="8 0">Toggle first</Button>
          <Button Command="{Binding ToggleSeries1Command}" Margin="8 0">Toggle second</Button>
          <Button Command="{Binding ToggleSeries2Command}" Margin="8 0">Toggle third</Button>
      </StackPanel>
      <lvc:CartesianChart Grid.Row="1" Series="{Binding Series}" />
  </Grid>  
</UserControl>

Articles you might also find useful: