Gruped And Stacked Bars

sample image

View model


using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace ViewModelsSamples.StackedBars.Groups;

[ObservableObject]
public partial class ViewModel
{
    public ISeries[] Series { get; set; } =
    {
        new StackedColumnSeries<int>
        {
            Values = new List<int> { 3, 5, 3 },
            Stroke = null,
            StackGroup = 0 // mark
        },
        new StackedColumnSeries<int>
        {
            Values = new List<int> { 4, 2, 3 },
            Stroke = null,
            StackGroup = 0 // mark
        },
        new StackedColumnSeries<int>
        {
            Values = new List<int> { 4, 6, 6 },
            Stroke = null,
            StackGroup = 1 // mark
        },
        new StackedColumnSeries<int>
        {
            Values = new List<int> { 2, 5, 4 },
            Stroke = null,
            StackGroup = 1 // mark
        }
    };

    public Axis[] XAxis { get; set; } =
    {
        new Axis
        {
            LabelsRotation = -15,
            Labels = new[] { "Category 1", "Category 2", "Category 3" }
        }
    };
}

using Eto.Forms;
using LiveChartsCore.SkiaSharpView.Eto;
using ViewModelsSamples.StackedBars.Groups;

namespace EtoFormsSample.StackedBars.Groups;

public class View : Panel
{
    private readonly CartesianChart cartesianChart;

    public View()
    {
        var viewModel = new ViewModel();

        cartesianChart = new CartesianChart
        {
            Series = viewModel.Series,
            XAxes = viewModel.XAxis,
        };

        Content = cartesianChart;
    }
}

Articles you might also find useful: