• Stars
    star
    1,009
  • Rank 45,557 (Top 0.9 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Resources for visualizing data using C# and the .NET platform

C# Data Visualization

  • This repository is a collection of C# code examples that draw graphics to display data

  • Additional resources are available at https://swharden.com/csdv/

Graphics Simulations

These examples were created for the C# Data Visualization Website and mostly involve creating rendering-library-agnostic models of complex systems, then developing rendering systems that can display the models.

Project Screenshot
Mystify Your Mind with C# - The classic screensaver implemented using both OpenGL and System.Drawing. See C# Data Visualization Website for details.
Game of Life in C# - Conway's Game of Life is a zero-player video game that uses a few basic rules to determine if cells live or die based on the density of their neighbors. In this project we create Life using C# and System.Drawing. See C# Data Visualization Website for details.
Boids in C# - This project implements the Boids flocking algorithm in C# to create an interesting procedural animation of bird-drones (boids) scurrying about the screen. See C# Data Visualization Website for details.
Boids in C# with SkiaSharp - This project is an extension of the original boids project that uses an abstracted rendering system supporting SkiaSharp and OpenGL for hardware-accelerated rendering. See C# Data Visualization Website for details.
Spline Interpolation with C# - This project demonstrates how to create a smooth curve from a rough set of X/Y points using cubic spline interpolation. The interpolation code used here is in a .NET Standard 2.0 library, and the interactive GUI is a WinForms App using ScottPlot.

Drawing with Different Graphics Technologies

Drawing Graphics from Scratch

Description Screenshot
Create a bitmap by editing bytes in memory and save the resulting image to disk without using any image manipulation library dependency

Drawing Graphics with Maui.Graphics

These examples use Microsoft.Maui.Graphics package to provide cross-platform drawing in .NET Core and .NET Framework applications.

Description Screenshot
Draw with Maui.Graphics in Windows Forms, WPF, and MAUI apps - This project encapsulates drawing logic in a .NET Standard library using Maui.Graphics (with no dependency on System.Drawing). This common library is then referenced by separate Maui, Windows Forms, WPF, and console apps to display images and animations.
Audio Level Monitor with Maui.Graphics - This project uses NAudio to continuously sample the default microphone device, calculate the maximum intensity, and display it in a Windows Forms application using the SkiaSharp OpenGL control.
Microphone FFT Display with Maui.Graphics - This project uses NAudio to continuously sample the default microphone device, calculate the Fast fourier transform (FFT), and display the result in a Windows Forms application using the SkiaSharp OpenGL control.
Life with Maui.Graphics - This implementation of Conway's Game of Life uses an isolated class library to encapsulate the game board's logic and rendering methods, and a separate Windows Forms application to provide the interactive GUI to display the board using SkiaSharp and OpenGL.
Graphics Model Viewer - This project has a .NET Standard library of graphics models containing simulation logic and rendering methods, and multiple GUI applications (Windows Forms, WPF, etc.) that display them using different rendering technologies.
Compare Maui.Graphics Skia rendering performance in Windows Forms with and without OpenGL - A test pattern of 10,000 anti-aliased semi-transparent lines is used to evaluate framerate performance of the skControl compared to the skglControl. On my system the standard control is over 6 times slower than the OpenGL control (3 Hz vs 20 Hz).

Drawing in WPF Applications

Description Screenshot
Drawing Lines with WPF is a minimal-case example to demonstrate how to add primitive shapes to a canvas in a WPF application

Drawing with SkiaSharp and OpenGL

System.Drawing uses the GDI+ backend to draw on the screen. It is convenient because it is been around forever and is easily supported by .NET, but it does not perform well in parallel environments or with large bitmaps (e.g., full screen). See this page for a thorough description of its limitations. Most examples on this page use GDI+ to create images. For a long time System.Drawing was limited to .NET Framework applications, but in 2018 the System.Drawing.Common package brought System.Drawing support to .NET Core.

SkiaSharp is a cross-platform .NET API for drawing with Skia, an open-source 2D drawing library developed by Google. SkiaSharp has an OpenGL control which allows hardware-accelerated rendering using OpenGL out of the box without requiring any OpenGL knowledge.

Description Screenshot
Drawing with SkiaSharp and OpenGL - This program demonstrates how to vastly outperform GDI+ (System.Drawing) when drawing thousands of semi-transparent lines at full-screen window sizes.

Drawing in Blazor with WebAssembly

Client-side Blazor lets graphics models written in C# compile-down to WebAssembly that can run in the browser on a static website. No special hosting is required! At the time of writing client-side Blazor is on the bleeding edge of development, and performance is mediocre. For intense rendering jobs in the browser JavaScript is still required, but for simple tasks you can define graphics models in C# and render them with a HTML Canvas API without ever learning C#

Description Screenshot
Animation in the Browser with Blazor WebAssembly and HTML Canvas (see blog post and live demo) - This program demonstrates how to write a graphics model in C# and render it using the Blazor.Extensions.Canvas to draw on a HTML canvas. See the blog post for details
Blazor Boids in your Browser (see blog post and live demo) - demonstrates how to use a C# graphics model with .NET code managing business logic and a JavaScript render method which uses the high speed HTML5 canvas to do the drawing.
Mystify your Browser with Blazor (see blog post and live demo) The classic Windows 3 screensaver now runs in the browser! The graphics model is in C# and uses Blazor bindings to control various settings. Blazor tells JavaScript what to render (using JSON) and JavaScript draws colored lines on a HTML canvas.
Google Charts in Blazor (see blog post and live demo) shows how to generate data in C# and display it interactively in the browser using Google Charts

Visualizing Audio in C#

Description Screenshot
Audio Monitor - Demonstrates how to connect to an audio device using NAudio and plot the levels in real time using ScottPlot
FFT Monitor - Extends the audio monitor project by using FftSharp to calculate the frequency component of live microphone audio and display the result using ScottPlot
Plotting Audio Amplitude - This example uses NAudio to access the sound card, calculates the amplitude of short recordings, then graphs them continuously in real time with ScottPlot. This project is a good place to get started to see how to interface audio input devices.
Plotting Audio Values - This example uses NAudio to access the sound card and plots raw PCM values with ScottPlot. These graphs contain tens of thousands of data points, but remain fully interactive even as they are being updated in real time.
Plotting Audio FFT - This example continuously plots the frequency component of an audio input device. The NAudio library is used to acquire the audio data and process the FFT and ScottPlot is used for the plotting.
Microphone Level Monitor - This console application uses NAudio to continuously monitor the microphone and display audio levels by printing characters to the screen. Examples are provided for mono and stereo audio inputs.

Independent Projects

Some code examples started in this repository and have matured into their own projects

Project Screenshot
ScottPlot is an interactive plotting library for .NET. If you're just looking for an easy way to interactively display some data on a graph using C#, ScottPlot might be for you!
Spectrogram is a simple spectrogram library for .NET. Specrogram converts signals (typically audio) into the frequency-domain and makes it easy to display spectrograms as 2D images. Spectrogram is fast enough to display the audio spectrum in real time.
Sound Card ECG uses scottplot to interactively display the soundcard signal in real time
HHSharp is an interactive Hodgkin-Huxley neuron simulator

Older Projects

⚠️ Code quality warning: This section contains projects and notes I created when I was first learning how to draw graphics with C#. They work, but likely have poor code quality. I share them here in case someone may find them useful, but they should certainly not be deeply studied or accepted as best practice.

Description Screenshot
Is a point inside a rotated rectangle? This Windows Forms application demonstrates how to rotate a rectangle around an arbitrary point then perform mouse tracking and hit detection. This example uses Maui.Graphics and SkiaSharp with OpenGL.
Drawing Lines - This project demonstrates a simple way to draw lines in a Windows Form. Here we create a Bitmap then use a Graphics object to draw lines on it. The Bitmap is then assigned to PictureBox.Image and displayed to the user.
Drawing with the Mouse - This project uses a PictureBox's MouseMove event handler to create a MSPaint-like drawing surface with only a few lines of code.
Plotting on a 2D Coordinate System - A simple but challenging task when plotting data on a bitmap is the conversion between 2D data space and bitmap pixel coordinates. If your axis limits are -10 and +10 (horizontally and vertically), what pixel position on the bitmap corresponds to (-1.23, 3.21)? This example demonstrates a minimal-case unit-to-pixel method and uses it to plot X/Y data on a bitmap.
Modifying Bitmap Data in Memory - Bitmaps in memory have a certain number of bytes per pixel, so they're easy to convert to/from byte arrays. This example shows how to convert a Bitmap to a byte array, fill the array with random values, and convert it back to a Bitmap to display in a PictureBox. This method can be faster than using drawing methods like GetPixel and PutPixel.
Setting Pixel Intensity from a Value - This example shows how to create an 8-bit grayscale image where pixel intensities are calculated from a formula (but could easily be assigned from a data array). This example also demonstrates the important difference between Bitmap width and span when working with byte positions in memory.
Graphing Data with GnuPlot from C++ isn't Csharp-specific, but can be translated to any programming language. It demonstrates how easy it is to graph data from any programming language by saving it as a text file then launching gnuplot on it. Advanced data control and styling can be set with command line arguments (compiled-in), or defined in script files which give the end user the ability to modify styling without modifying the source code.
Realtime Microphone FFT Analysis is a new version of an older concept. This project uses a modern ScottPlot which has many improvements over older projects listed here.
DataView 1.0 is an interactive plotting control written using only the standard library. It allows panning/zooming by left-click-dragging the axis labels, moving the scrollbars, clicking the buttons, and also through right-click menus on the axis labels. Interactive draggable markers are also included. This control was designed to look similar to the commercial software ClampFit. I have decided to re-code this project from the ground-up, but the solution is frozen as-is (in a quite useful state) and the project page contains many notes of considerations and insights I had while developing it.
QRSS Spectrograph produces spectrographs which are very large (thousands of pixels) and very high frequency resolution (fractions of a Hz) intended to be used to decode slow-speed (1 letter per minute) frequency-shifting Morse code radio signals, a transmission mode known as QRSS. While functional as it is, this project is intended to be a jumping-off point for anybody interested in making a feature-rich QRSS viewer.
realtime audio spectrograph listens to your default recording device (microphone or StereoMix) and creates a 2d time vs. frequency plot where pixel values are relative to frequency power (in a linear or log scale). This project is demonstrated in a YouTube video. This example is not optimized for speed, but it is optimized for simplicity and should be very easy to learn from.
Microphone Level Monitor - This console application uses NAudio to continuously monitor the microphone and display audio levels by printing characters to the screen. Examples are provided for mono and stereo audio inputs.
realtime audio level meter uses NAudio to provide highspeed access to the microphone or recording device. This project is a minimal-case project intended to remind the author how to effeciently interact with incoming audio data.
realtime graph of microphone audio (RAW and FFT) Here I demonstrate a minimal-case example using the interactive graphing framework (below) to display audio values sampled from the microphone in real time. FFT () is also calculated and displayed interactively. See this project demonstrated on YouTube. Audio capture is achieved with nAudio and FFT with Accord. See FFT notes for additional details.
linear data speed rendering I greatly increased speed by drawing only single vertical lines (of small range min and max values) when the point density exceeds the horizontal pixel density. This is only suitable for evenly-spaced linear data (which is exactly what my target applications will be plotting). Performance is great, and there is plenty of room for improvement on the coding side too. AddLineXY() will be used to manually draw a line between every X,Y point in a list. AddLineSignal() graphs data from huge amounts of linear data by only graphing vertical lines.
intelligent axis labels This from-scratch re-code has separate classes for core plotting routines, data generation, and axis manipulation. Tick marks are quite intelligent as well. Included is a GUI demo (shown) as well as a 6 line console application which does the same thing (saving the output to a .jpg file instead of displaying it interactively).
interactive electrophysiology data Nearly identical to the previous example, except that there is a CSV button which loads an arbitrary string of values from data.csv if it is saved in the same folder as the exe. With minimal effort this program could be modified to directly load from ATF (Axon Text Format) files. With a little more effort, you could interface ABF files with the Axon pCLAMP ABF SDK.
interactive pan and zoom The ScottPlot class now has an advanced axis system. This makes it easily to set the viewing window in unit coordinates (X1, X2, Y1, Y2) and also do things like zoom and pan. This example was made to demonstrate these functions, as well as compare the speed of interactive graph manipulation at different sizes and with different quality settings. Although the GUI has many features, Form1.cs is not overwhelmingly complex.
stretchy line plot In this demo some random points are generated and scrolled (similar to numpy's roll method). Although the result looks simple, there is some strong thought behind how this example is coded. All the graphing code is encapsulated by the ScottPlot class of swhPlot.cs. The code of the GUI itself Form1.cs is virtually empty. My thinking is that from here I'll work on the graphing class, keeping gui usage as simple as possible. Note: plotting 321 data points I'm getting about 300Hz drawing rate with anti-aliasing off and 100Hz with it on
basic buffered line plot graphs data by creating a bitmap buffer, drawing on it with System.Drawing.Graphics (mostly DrawLines()) with customizable pens and quality (anti-aliasing), then displaying it onto a frame. The frame is resizable, which also resizes the bitmap buffer. Screen updates are timed and reported (at the bottom) so performance at different sizes can be assessed.
highspeed bitmap pixel access requires some consideration. This minimal-case project demonstrates how to set individual pixels of a bitmap buffer using the slower (simpler) setpixel method and the faster (but more complex) lockbits method. Once a bitmap buffer is modified, it is then applied to a pictutremap.

More Repositories

1

FftSharp

A .NET Standard library for computing the Fast Fourier Transform (FFT) of real or complex data
C
313
star
2

Spectrogram

.NET library for creating spectrograms (visual representations of frequency spectrum over time)
C#
311
star
3

Python-GUI-examples

A growing collection of bare-bones GUI examples for python (PyQt4, Python 3)
Python
238
star
4

AVR-projects

A collection of standalone AVR projects written in C
C
161
star
5

pyABF

pyABF is a Python package for reading electrophysiology data from Axon Binary Format (ABF) files
Jupyter Notebook
101
star
6

diyECG-1opAmp

A surprisingly good ECG circuit using a single op-amp and some Python software
Python
98
star
7

SoundCardECG

Display ECG signals in real time using a sound card interface and an AD8232
C#
85
star
8

pyHH

A simple Python implementation of the Hodgkin-Huxley spiking neuron model
Python
36
star
9

code-notes

notes and reusable code for various programming languages
C++
34
star
10

QuickPlot

Experimental Plotting Library for .NET
C#
31
star
11

FtdiSharp

A .NET library for interfacing FTDI USB controller ICs
C#
25
star
12

SWHLab

Python tools for analysis of whole-cell patch-clamp electrophysiological data
Python
20
star
13

SeriPlot

Realtime Serial Data Plotter
C#
20
star
14

Local-LLM-csharp

Run a LLM locally to answer questions about documents using C#
HTML
19
star
15

USB-Counter

Open-source USB frequency counter
C
18
star
16

BasicTimer

A basic timer app for Windows
C#
17
star
17

pyScreenCapture

Screen capture video (with cursor) using Python
Python
17
star
18

md2html-php

A flat-file dynamic markdown-to-HTML site generator using PHP
PHP
15
star
19

pyABFauto

Automatic analysis (and graphing) of ABF files
Python
14
star
20

RasPi-Frequency-Counter

Raspberry PI RF Frequency Counter with Python Interface
Python
14
star
21

HHSharp

Interactive Hodgkin-Huxley neuron simulator
C#
13
star
22

FSKview

A high resolution spectrogram for viewing FSK signals in real time
C#
13
star
23

pyTENMA

Python interface to TENMA multimeter serial data
Python
12
star
24

QRSS-VD

QRSS Viewer for Python 2
Python
12
star
25

Mystify

A modern implementation of a classic screensaver
C#
12
star
26

SwarmFit

A .NET package for fitting curves to data using particle swarm optimization
C#
11
star
27

FTFlash

A tool for reading and writing data in SPI flash memory chips using a FT232H
C#
9
star
28

QRSSplus

QRSS Plus: live QRSS grabbers from around the world
C#
9
star
29

ADC-10-F103C

Software and Notes for 10-Channel ADC Board
C#
9
star
30

WsprSharp

.NET Standard library for encoding/decoding messages using the WSPR protocol
HTML
8
star
31

QRSS-hardware

A collection of resources related to QRSS hardware (TX and RX)
C
8
star
32

LJPcalc

Liquid Junction Potential Calculator
C#
8
star
33

ABFview

Electrophysiology data viewer for Axon Binary Format (ABF) files
C#
7
star
34

SciTIF

A .NET library for working with scientific image data in TIFF files
C#
7
star
35

CsvPlot

Interactively display data from CSV files
C#
7
star
36

NumberSpeaker

Arduino library for reading numbers using a speaker
C
5
star
37

AbfSharp

A .NET interface for Axon Binary Format (ABF) files
HTML
5
star
38

pyHamLog

ham radio logging software with a web interface (designed for school club roundup)
Python
5
star
39

repo-badge

Display GitHub repository statistics using Vanilla JS
5
star
40

swharden

Scott W Harden on GitHub
4
star
41

ScanAGator

A tool for calculating calcium levels (Ξ”F/F) from two-photon line scans
C#
4
star
42

ABF-Tag-Editor

A standalone application to modify comment tags in ABF files
C#
4
star
43

QRSS-Uploader

Uploads QRSS images to a FTP server every 10 minutes
C#
4
star
44

vsABF

A modern .NET interface to files in the Axon Binary Format (ABF)
C#
4
star
45

ImageJ-Python-plugin

boilerplate python plugin for ImageJ / FIJI
Python
4
star
46

Washcloth

A .NET Standard library for reading XML documentation using reflection
C#
4
star
47

Lopora

QRSS Beacon Reception Program
Python
4
star
48

FlaskABF

Python-based web application to browse and analyze electrophysiology data
HTML
4
star
49

LivePictureViewer

A picture viewer that rapidly updates when the image file on disk changes
C#
4
star
50

webinspect

Python module to allow users to inspect python objects in a web browser
Python
4
star
51

SWHarden.com

The personal website of Scott W Harden
HTML
4
star
52

ROI-Analysis-Pipeline

Tools for automated analysis of fluorescent microscopy data
Shell
3
star
53

ABF-SDK

Resources for working with Axon Binary Format (ABF) Files
C++
3
star
54

QRSSplus-Downloader

A Windows application to automatically download QRSS grabber images
C#
3
star
55

Tmoji

A taskbar app to quickly copy emoji and special symbols
C#
3
star
56

WpfPingMonitor

Windows application to display ping latency
C#
3
star
57

RasterSharp

A .NET library for working with images in memory
C#
3
star
58

ephys-projects

personal projects related to electrophysiology data analysis and visualization
C#
2
star
59

NDepend-Badges

C#
2
star
60

Statix

C# Static Site Generator
C#
2
star
61

SWHarden-User-Controls

A collection of custom user controls for .NET
C#
2
star
62

psk-experiments

Phase-shift keying (PSK) notes and resources
C#
2
star
63

Csharp-Image-Analysis

Code examples and notes for analyzing image data using C#
C#
2
star
64

StarGraph

A cloud application for generating historical graphs of GitHub stars
C#
2
star
65

Palila

Minimal, hackable, dependency-free Python static site generator
HTML
2
star
66

ABF-Scale-Fixer

An application to modify header values of ABF2 files
C#
2
star
67

iot-weather-station

Wi-Fi weather station using NodeMCU and ESP8266
HTML
2
star
68

ScottPlotStats

Azure Functions for logging and plotting ScottPlot NuGet package downloads
C#
2
star
69

memtest

Notes and code for calculating cell membrane parameters from electrophysiological recordings
Jupyter Notebook
2
star
70

JLJP

Java application for calculating liquid junction potential (LJP)
Java
2
star
71

Java-Boilerplate

Example Java desktop app with tests and CI using GitHub Actions
Java
1
star
72

swharden.com-2021

code and resources related to my personal website
PHP
1
star
73

Bootstrapped-KS2

Tools for bootstrapping the Kolmogorov-Smirnov statistic on 2 samples
C#
1
star
74

duplicate-code-finder

A simple Python script to identify duplicate lines in the code base of any programming language
Python
1
star
75

AliCalc

Aliquot Calculator for Electrophysiology
HTML
1
star
76

patch

A Student's Guide to Patch-Clamp Electrophysiology
HTML
1
star
77

QRSS-Viewer

An open source QRSS spectrograph for Windows
C#
1
star
78

Microscopy

miscellaneous notes and tools to aid the scientific microscopist
Python
1
star
79

ColorblindEnhancer

A Windows tool that enhances color perception for people with color vision deficiencies
C#
1
star
80

originpro

Source code for the originpro Python package
Python
1
star
81

Maui.Graphics

Source for https://maui.graphics
HTML
1
star
82

SWHLabPHP

Dynamically generated web platform to browse electrophysiology data
PHP
1
star
83

govee-plot

Tools for interactively plotting Govee temperature and humidity data
Jupyter Notebook
1
star
84

double-pendulum-dotnet

C# implementation of the double pendulum problem
C#
1
star
85

AbfAuto

automated analysis of electrophysiology data in ABF files
C#
1
star
86

AbfConvert

Tools for automated conversion of ABF files to ATF, CSV, and other useful formats
C#
1
star
87

MatrixWall

Falling green Unicode characters on a dark background implemented using Vanilla JavaScript
JavaScript
1
star
88

PrairieView-Quick-Loader

ImageJ plugin to quickly load multiphoton imaging data from PrairieView folders
Java
1
star
89

Exponential-Fit-CSharp

Exponential fit code examples using C#
C#
1
star
90

AbfVideo

Generate real-time video files from electrophysiology data
C#
1
star
91

qrss.org

A collection of resources for ultra-narrowband amateur radio experimentation
HTML
1
star
92

swharden.RoiSelect

A .NET Package that facilitates working with regions of interest (ROIs) for imaging data in GUI applications
C#
1
star
93

ABF-Spectrogram

Tools for generating FFTs and Spectrograms from ABF files
C#
1
star
94

GitHub-License-Checker

A web app for identifying GitHub repositories lacking license or other important files
HTML
1
star