Skip to content

The C# LiveCharts2 data visualization library plugin for Godot Game Engine

License

Notifications You must be signed in to change notification settings

Ilnazz/godot-live-charts

Repository files navigation

The LiveCharts2 for the Godot

As the official web-site says, the LiveCharts2 is a data visualization library for the .Net that can run across multiple devices and frameworks, It runs under the MIT license (free) and offers a paid package to improve performance and extend features.

The LiveCharts2 web-site: https://livecharts.dev

The LiveCharts2 source code: https://github.com/beto-rodriguez/LiveCharts2

Lvc for GodotLiveChartsForGodot

Prerequisites

Because this library is for the .Net platform, you need to make sure that you have created a C# solution as part of your Godot project.

Installation

  1. At this moment to install this library to your project as a plugin, you need download a build of this library for the desired version of .Net (6, 7 or 8) from builds directory and copy the live-charts plugin folder to the addons folder.

  2. Install the following NuGet packages:

<ItemGroup>
    <PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.6" />
    <PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.6" />
</ItemGroup>
  1. Add the following references to DLL's to your *.csproj file (it is needed because SkiaSharp.Views.Godot and LiveChartsCore.SkiaSharpView.Godot are not official yet):
<ItemGroup>
    <Reference Include="LiveChartsCore">
        <HintPath>addons\live_charts\libraries\LiveChartsCore.dll</HintPath>
    </Reference>
    <Reference Include="LiveChartsCore.SkiaSharpView">
        <HintPath>addons\live_charts\libraries\LiveChartsCore.SkiaSharpView.dll</HintPath>
    </Reference>
    <Reference Include="LiveChartsCore.SkiaSharpView.Godot">
        <HintPath>addons\live_charts\libraries\LiveChartsCore.SkiaSharpView.Godot.dll</HintPath>
    </Reference>
    <Reference Include="SkiaSharp.Views.Godot">
        <HintPath>addons\live_charts\libraries\SkiaSharp.Views.Godot.dll</HintPath>
    </Reference>
</ItemGroup>
  1. Finally, your *.csproj file should look like this:
<Project Sdk="Godot.NET.Sdk/4.2.0">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net8.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
    <PackageReference Include="SkiaSharp" Version="2.88.6" />
    <PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.6" />
    <PackageReference Include="SkiaSharp.Views.Desktop.Common" Version="2.88.6" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="LiveChartsCore">
      <HintPath>addons\live_charts\libraries\LiveChartsCore.dll</HintPath>
    </Reference>
    <Reference Include="LiveChartsCore.SkiaSharpView">
      <HintPath>..\New Game Project\addons\live_charts\libraries\LiveChartsCore.SkiaSharpView.dll</HintPath>
    </Reference>
    <Reference Include="LiveChartsCore.SkiaSharpView.Godot">
      <HintPath>addons\live_charts\libraries\LiveChartsCore.SkiaSharpView.Godot.dll</HintPath>
    </Reference>
    <Reference Include="SkiaSharp.Views.Godot">
      <HintPath>addons\live_charts\libraries\SkiaSharp.Views.Godot.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>
  1. Rebuild your project and enable live-charts plugin.

Usage

  1. Create a View Model:
using System.Collections.Generic;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace NewGameProject;

public class ViewModel
{
    // Create the collection of series to use in chart
    public IEnumerable<ISeries> Series { get; } = new ISeries[]
    {
        new LineSeries<double>
        {
            Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },
            Fill = null
        }
    };
}
  1. Create a new User Interface scene:

creating-the-user-scene

  1. Add a CartesianChart to the scene:

image

  1. Attach the new script to the newly created scene with the following code:
using Godot;
using GodotPlugins.LiveCharts;
using LiveChartsCore.Measure;

namespace NewGameProject;

public partial class Sample : Control
{
    public override void _Ready()
    {
        // Instantiate the view model for the chart
        var viewModel = new ViewModel();

        // Get the chart node
        var cartesianChart = (CartesianChart)FindChild("CartesianChart");

        // Set the chart series from the view model property
        cartesianChart.Series = viewModel.Series;
        
        // Optionally, set chart's legend position
        cartesianChart.LegendPosition = LegendPosition.Right;
    }
}
  1. Run the scene:

image

More samples

You can see all official LiveCharts2 samples adapted to Godot in action in the samples/Samples folder. Just run MainScene.

Demo

Some technical details

The LiveCharts2 is designed as a UI-framework independent library. To accomplish this, it uses the feature-rich SkiaSharp library (which is C# bindings for the Google's Skia 2D graphics library) as a rendering engine. So, it can be quite easily ported to .Net frameworks/platforms where it is possible to use SkiaSharp. To use the SkiaSharp, there are separate so-called views for different frameworks Just like the SkiaSharp, the LiveCharts2 provides different views for different frameworks.

There was no the such SkiaSharp view for the Godot, so I created it: SkiaSharp.Views.Godot. After that, I created the LiveCharts2 view for the Godot: LiveChartsCore.SkiaSharpView.Godot based on the SkiaSharp view for the Godot.

I have recently updated the LiveChartsCore.SkiaSharpView.Godot, and I plan to update the plugin builds in this repository in the near future.

About

The C# LiveCharts2 data visualization library plugin for Godot Game Engine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published