Dynamic Visibility

Notice this web site wraps every sample using the ContentPage class, but LiveCharts controls can be used inside any container, this sample also follows a Model-View-* pattern.

sample image

View model

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace ViewModelsSamples.General.Visibility;

public class ViewModel
{
    public List<ISeries> Series { get; set; } = new()
    {
        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
        }
    };

    public void ToogleSeries0()
    {
        Series[0].IsVisible = !Series[0].IsVisible;
    }

    public void ToogleSeries1()
    {
        Series[1].IsVisible = !Series[1].IsVisible;
    }

    public void ToogleSeries2()
    {
        Series[2].IsVisible = !Series[2].IsVisible;
    }

    // The next commands are only to enable XAML bindings
    // they are not used in the WinForms sample
    public ICommand ToggleSeries0Command => new Command(o => ToogleSeries0());

    public ICommand ToggleSeries1Command => new Command(o => ToogleSeries1());

    public ICommand ToggleSeries2Command => new Command(o => ToogleSeries2());
}

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>

Articles you might also find useful: