csharp-data-visualization

repository·main·Indexed 22 days ago

https://github.com/swharden/csharp-data-visualization

A collection of C# code examples for data visualization and graphics rendering. It demonstrates cross-platform drawing with Microsoft.Maui.Graphics, high-performance rendering using SkiaSharp and OpenGL, web-based visualization via Blazor WebAssembly, and audio visualization using NAudio, FftSharp, and ScottPlot. The repository also covers spline interpolation, DataFrame usage in .NET Interactive Notebooks, and specialized simulators like HHSharp and Spectrogram.

Tokens
62.9K
Snippets
172
Records
243
Agent score
77%

What's inside csharp-data-visualization

  1. Overview of C# Data Visualization examples

    main

    This repository is a collection of C# code examples designed to demonstrate various ways to draw graphics to display data. The projects range from graphics simulations (like Boids or Game of Life) to specific technology implementations using different rendering engines.

    Key areas covered include:

    • Graphics Simulations: Rendering-library-agnostic models of complex systems.
    • Cross-Platform Drawing: Using Microsoft.Maui.Graphics for Windows Forms, WPF, and MAUI.
    • High-Performance Rendering: Using SkiaSharp and OpenGL.
    • Web-Based Visualization: Using Blazor WebAssembly with HTML Canvas.
    • Audio Visualization: Interfacing with audio devices using NAudio and plotting with ScottPlot.
  2. Overview of DevExpress WPF Charting

    main
    The DevExpress WPF Charting package provides user controls for creating interactive and animated charts within .NET applications. It is part of a larger suite of UI components for Windows Presentation Foundation (WPF) and Windows Forms. The library is characterized by high levels of built-in animation (e.g., bars growing into position, lines growing, and markers appearing) which may be suitable for consumer-facing applications like weather apps or video game score histories, though potentially distracting for scientific applications.
  3. Overview of Telerik UI Chart for .NET

    main

    Telerik provides a suite of commercial UI components for data visualization, specifically the ChartView control. It is available for both WPF and WinForms applications.

    Key characteristics:

    • Theming & Appearance: Designed for easy theming and high-quality visual appearance.
    • Animations: Supports animations for simple data sets.
    • Interactivity: Includes built-in default interactivity such as left-click-drag for zooming/panning and scroll-wheel for zooming.
    • Use Case Note: While visually polished, it may not be optimized for high-performance scientific charting or extremely large datasets.
  4. Spline Interpolation with C#

    main

    This project provides implementations for spline interpolation using C#. Spline interpolation is a method of constructing new data points within the range of a discrete set of known data points to create a smooth curve.

    For a detailed explanation of the mathematical concepts and the implementation logic, refer to the original blog post: https://swharden.com/blog/2022-01-22-spline-interpolation

  5. Draw graphics cross-platform with Maui.Graphics

    main

    The Microsoft.Maui.Graphics package provides a way to perform cross-platform drawing in both .NET Core and .NET Framework applications.

    Common usage patterns in this repository include:

    • Encapsulated Logic: Creating a .NET Standard library that contains drawing logic using Maui.Graphics (without a dependency on System.Drawing). This library can then be referenced by multiple GUI targets like Maui, Windows Forms, WPF, or even console apps.
    • Hardware Acceleration: Using SkiaSharp OpenGL controls within Windows Forms to render Maui.Graphics content for improved performance (e.g., comparing skControl vs skglControl).
    • Audio Monitoring: Combining NAudio for sampling with Maui.Graphics for real-time visual feedback.
  6. Use ScottPlot.Palette for color management

    main

    In ScottPlot 4.1.24, the ScottPlot.Palette module was introduced to manage color schemes. This replaces the older ScottPlot.Drawing.Palette module. While the old module remains available and will not be marked obsolete until ScottPlot 5, it is recommended to use ScottPlot.Palette for new implementations and cookbook recipes.

    // Use the new Palette module
    ScottPlot.Palette myPalette = ...;
  7. SciChart Performance and Hardware Acceleration

    main

    SciChart is designed for high-performance interactive charting, capable of handling datasets with billions of points. It utilizes hardware acceleration via:

    • DirectX on Windows
    • OpenGL on Android
    • Metal on iOS

    It is suitable for real-time data scenarios, such as simulating live incoming data (e.g., 1,000 points every 20 ms) while maintaining comfortable interactive frame rates.

  8. Compare performance of C# graphics libraries

    main

    To evaluate the performance of different rendering libraries, use a benchmark involving drawing a high volume of random lines on a colored background.

    Benchmark Parameters:

    • Fixed Size: e.g., 800x600.
    • Background Color: Use a non-black color (e.g., #003366) to ensure the background is actually drawn.
    • Line Properties: Random integer coordinates, random integer width (1-10px), and random color/alpha.
    • Line Counts: Test with varying scales such as 10, 1k, 10k, or 100k to distinguish between systems sensitive to total area vs. total object count.
    • Optimization Rules:
      • Render in a single thread.
      • Create Bitmaps once (do not recreate on every render).
      • Reuse styling objects across lines within the render loop rather than instantiating new ones for every line.
    • Measurement: Include display time (e.g., the time taken to copy a buffer to a Bitmap) in the total render time.
  9. Use System.Drawing.Primitives for cross-platform data types

    main
    If you need to maintain cross-platform compatibility for your APIs but do not require actual rendering capabilities, you can use the System.Drawing.Primitives package. This package provides cross-platform support for basic types like Color, Point, and Rect without the Windows-only rendering dependencies of System.Drawing.Common.