Table of Contents

Class ChartSceneBuilder

Namespace
TwBlazor.Charting
Assembly
TwBlazor.dll

Collects the marks, data points, axes, legend and table of a ChartScene.

public sealed class ChartSceneBuilder
Inheritance
ChartSceneBuilder
Inherited Members

Remarks

The first group of methods adds raw marks at plot percentages. The second group works in "band and value" terms and respects Horizontal, so one chart definition can draw both as columns and as bars.

Constructors

ChartSceneBuilder()

public ChartSceneBuilder()

Properties

Horizontal

Gets or sets whether values run left to right with categories stacked top to bottom (bars), instead of values running bottom to top with categories left to right (columns).

public bool Horizontal { get; set; }

Property Value

bool

Shape

Gets or sets the proportions of the plot area.

public ChartShape Shape { get; set; }

Property Value

ChartShape

Table

Gets or sets the chart's data as a table.

public ChartTable? Table { get; set; }

Property Value

ChartTable

XAxis

Gets or sets the labels along the bottom of the plot area.

public ChartAxis? XAxis { get; set; }

Property Value

ChartAxis

YAxis

Gets or sets the labels along the left of the plot area.

public ChartAxis? YAxis { get; set; }

Property Value

ChartAxis

Methods

Add(IChartMark)

Adds any mark.

public void Add(IChartMark mark)

Parameters

mark IChartMark

BandAxis(IReadOnlyList<string>, ChartBand, string?)

Adds category axis labels, one per slot. Along the bottom, labels are thinned out once there are too many to read.

public void BandAxis(IReadOnlyList<string> labels, ChartBand band, string? title = null)

Parameters

labels IReadOnlyList<string>
band ChartBand
title string

BandDatum(double, double, string, IReadOnlyList<ChartDatumRow>, ChartHover)

Adds an interactive data point covering one whole category slot.

public void BandDatum(double band, double size, string title, IReadOnlyList<ChartDatumRow> rows, ChartHover hover = ChartHover.Highlight)

Parameters

band double
size double
title string
rows IReadOnlyList<ChartDatumRow>
hover ChartHover

Bar(double, double, double, double, ChartColor, ChartCorner?, bool)

Adds a bar across the category axis at band, spanning from to to on the value axis. Unless corner is given, only the data end is rounded. Set gap to false for a bar layered over another, which needs no separating gap.

public void Bar(double band, double thickness, double from, double to, ChartColor color, ChartCorner? corner = null, bool gap = true)

Parameters

band double
thickness double
from double
to double
color ChartColor
corner ChartCorner?
gap bool

Baseline(double)

Adds the baseline that bars grow from.

public void Baseline(double value)

Parameters

value double

Build()

Creates the scene.

public ChartScene Build()

Returns

ChartScene

Datum(double, double, double, double, string, IReadOnlyList<ChartDatumRow>, ChartHover)

Adds an interactive data point, positioned by its center.

public void Datum(double x, double y, double width, double height, string title, IReadOnlyList<ChartDatumRow> rows, ChartHover hover = ChartHover.Highlight)

Parameters

x double
y double
width double
height double
title string
rows IReadOnlyList<ChartDatumRow>
hover ChartHover

Datum(ChartDatum)

Adds an interactive data point built by the caller, such as one with a tooltip anchor.

public void Datum(ChartDatum datum)

Parameters

datum ChartDatum

Dot(double, double, ChartColor, double, double, string?)

Adds a dot. diameter is in pixels.

public void Dot(double x, double y, ChartColor color, double diameter = 10, double opacity = 1, string? title = null)

Parameters

x double
y double
color ChartColor
diameter double
opacity double
title string

Glyph(double, double, Icon, ChartColor, double)

Adds an icon. size is in pixels.

public void Glyph(double x, double y, Icon icon, ChartColor color, double size = 20)

Parameters

x double
y double
icon Icon
color ChartColor
size double

Legend(string, ChartColor, int?, bool)

Adds a legend entry.

public void Legend(string label, ChartColor color, int? seriesIndex = null, bool hidden = false)

Parameters

label string
color ChartColor
seriesIndex int?
hidden bool

Line(double, double, double, double, ChartColor, ChartStroke)

Adds a straight line.

public void Line(double x1, double y1, double x2, double y2, ChartColor color, ChartStroke stroke = ChartStroke.Hairline)

Parameters

x1 double
y1 double
x2 double
y2 double
color ChartColor
stroke ChartStroke

Marker(double, double, ChartColor, double, double, string?)

Adds a dot at a band and value position.

public void Marker(double band, double value, ChartColor color, double diameter = 10, double opacity = 1, string? title = null)

Parameters

band double
value double
color ChartColor
diameter double
opacity double
title string

Path(string, ChartColor, bool, double, ChartStroke, bool, string?)

Adds an SVG path.

public void Path(string data, ChartColor color, bool filled = false, double opacity = 1, ChartStroke stroke = ChartStroke.Normal, bool outline = false, string? title = null)

Parameters

data string
color ChartColor
filled bool
opacity double
stroke ChartStroke
outline bool
title string

Point(double, double)

Converts a position along the category axis and a position along the value axis into a plot point.

public (double X, double Y) Point(double band, double value)

Parameters

band double
value double

Returns

(double X, double Y)

Rect(double, double, double, double, ChartColor, ChartCorner, double)

Adds a filled rectangle. For the less common options, pass a ChartRect to Add(IChartMark).

public void Rect(double x, double y, double width, double height, ChartColor color, ChartCorner corner = ChartCorner.None, double opacity = 1)

Parameters

x double
y double
width double
height double
color ChartColor
corner ChartCorner
opacity double

SectorDatum(ChartSector, string, IReadOnlyList<ChartDatumRow>, double?)

Adds an interactive data point that covers a ChartSector, so the pointer triggers it anywhere on the segment. Use it on a Square plot.

public void SectorDatum(ChartSector sector, string title, IReadOnlyList<ChartDatumRow> rows, double? anchorAngle = null)

Parameters

sector ChartSector
title string
rows IReadOnlyList<ChartDatumRow>
anchorAngle double?

Remarks

The tooltip points at the middle of the segment's thickness (65% of the way out on a wedge), at anchorAngle or halfway round the segment when that is not given.

Segment(double, double, double, double, ChartColor, ChartStroke)

Adds a line between two band and value positions.

public void Segment(double band1, double value1, double band2, double value2, ChartColor color, ChartStroke stroke = ChartStroke.Normal)

Parameters

band1 double
value1 double
band2 double
value2 double
color ChartColor
stroke ChartStroke

ShapeDatum(IReadOnlyList<(double X, double Y)>, string, IReadOnlyList<ChartDatumRow>, (double X, double Y)?)

Adds an interactive data point cut to an outline, so the pointer triggers it anywhere on an irregular shape such as an area, a ribbon or a hexagon.

public void ShapeDatum(IReadOnlyList<(double X, double Y)> outline, string title, IReadOnlyList<ChartDatumRow> rows, (double X, double Y)? anchor = null)

Parameters

outline IReadOnlyList<(double X, double Y)>

The corners of the shape, in order, as plot percentages.

title string

The title of the tooltip.

rows IReadOnlyList<ChartDatumRow>

The rows of the tooltip.

anchor (double X, double Y)?

The plot position the tooltip points at. Without one it sits above the middle of the shape.

Text(double, double, string, ChartAnchor, ChartBaseline, ChartTextTone)

Adds a text label. For pixel offsets and emphasis, pass a ChartText to Add(IChartMark).

public void Text(double x, double y, string text, ChartAnchor anchor = ChartAnchor.Middle, ChartBaseline baseline = ChartBaseline.Middle, ChartTextTone tone = ChartTextTone.Muted)

Parameters

x double
y double
text string
anchor ChartAnchor
baseline ChartBaseline
tone ChartTextTone

TipLabel(double, double, string, bool)

Adds a value label just past the data end of a bar.

public void TipLabel(double band, double value, string text, bool rising = true)

Parameters

band double
value double
text string
rising bool

ValueAxis(IReadOnlyList<ChartTick>, string?)

Adds value axis labels and gridlines at the given positions along the value axis.

public void ValueAxis(IReadOnlyList<ChartTick> ticks, string? title = null)

Parameters

ticks IReadOnlyList<ChartTick>
title string

ValueAxis(ChartScale, Func<double, string>, string?)

Adds value axis labels and gridlines from a scale.

public void ValueAxis(ChartScale scale, Func<double, string> format, string? title = null)

Parameters

scale ChartScale
format Func<double, string>
title string