
GG.Net Data Visualization
GG.Net lets Data Scientists and Developers create interactive and flexible charts for .NET and Blazor Web Apps.
Taking its inspiration from the highly popular ggpplot2 R package, GG.Net provides natively rich features for your Data Analysis Workflow. Build publication quality charts with just a few lines of code in C# and F#.
Learn more about GG.Net
Install
2.0 builds publish to GitHub Packages. That feed requires authentication even for public packages, so add a nuget.config next to your solution with a personal access token carrying the read:packages scope:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="ggnet" value="https://nuget.pkg.github.com/pablofrommars/index.json" />
</packageSources>
<packageSourceCredentials>
<ggnet>
<add key="Username" value="USERNAME" />
<add key="ClearTextPassword" value="TOKEN" />
</ggnet>
</packageSourceCredentials>
</configuration>
dotnet add package GGNet --prerelease
The 1.4.0 release remains on nuget.org.
The DSL
A plot is one fluent chain: PlotContext.Build(source, x, y) establishes the data source and default selectors, each Geom_* call adds a layer configured in place, Scale_* calls shape the axes and legends, and .Style() finishes the plot.
var plot = PlotContext.Build(points, o => o.X, o => o.Y)
.Geom_Line(strokeWidth: 2, color: "#23d0fc")
.Geom_HLine([1.0], y: o => o, label: o => "Baseline", lineType: LineType.Dashed)
.Scale_Y_Continuous(formatter: new DoubleFormatter("N2"))
.Style();
Conventions
xxxBy means data-driven. colorBy, fillBy, sizeBy, lineTypeBy take an aesthetic mapping (built by Scale_Color_Discrete, Scale_Fill_Continuous, …): the value is computed per item, trains a scale, and feeds the legend. The unsuffixed twin (color, fill, size, lineType) is a constant applied to the whole layer. When a mapping is present it wins for its own aesthetic; the constant then still serves as the base for other aesthetics' legend swatches (a line-type legend draws its swatches in the constant color), so setting both is meaningful rather than an error.
- Positional arguments stop at the selectors. Source and selector parameters (
x, y, ymin, open, …) may be passed positionally; every aesthetic, event, or option after them is passed by name. The signatures are wide by design — configuration lives in one call — and named arguments are what keep call sites readable and stable.
- The vocabulary is SVG's.
strokeWidth, opacity, fillOpacity, strokeOpacity, strokeColor mean exactly what they mean in SVG. width and height are reserved for geometric extent in data units (Geom_Bar, Geom_Tile, Geom_Violin, Geom_RidgeLine).
- Interactivity is a uniform block. Every data-mark geom takes
onclick, onmouseover, onmouseout, and (where a hover surface makes sense) tooltip. When tooltip is set and no explicit hover handlers are given, the default hover shows it. Annotation geoms (Geom_ABLine, Geom_HLine, Geom_VLine, Geom_Text) and statistical summaries (Geom_Boxplot, Geom_Violin, Geom_RidgeLine) deliberately take no event block.
Position ranges and updates
Log10 positions require positive finite data, limits, and view bounds. Nonpositive values and infinities throw GGNetUserException; filter those rows or choose a continuous scale. Existing NaN missing-point and line-gap behavior is retained. Nonfinite position extents and view windows are rejected before tick generation.
Automatic area ranges include their drawn baseline, which is zero in transformed coordinates (raw value one on a Log10 axis). Explicit limits and view windows still take precedence. Large finite numeric ranges use finite expansion and overflow-safe projection; very small, very large, or narrowly offset ranges use at most five evenly spaced major ticks. Expansion saturates at finite double endpoints. Equal view bounds receive singleton padding.
In Blazor, changing Context, Width, or Height requests a refresh in both interactive modes and preserves view windows when resizing. Static retains its initial frame. A context may be reused sequentially after headless export; use separate contexts for concurrently mounted plots.
Long time series