ChartImageRenderer Class

Draws the charts of Meziantou.Framework.Charts as images, or on a DrawingCanvas.

public static class ChartImageRenderer

Remarks

The plot is laid out with the fonts that draw it (ImageTextMeasurer), so the margins, the rotated labels and the truncated labels fit the text. Save the image in any format: image.Save("chart.png").

Methods

NameDescription
CreateMeasurer(ChartImageOptions?)Creates the text measurer of the fonts of the options, to lay a plot out with Plot.CreateScene.
DrawChart(DrawingCanvas, Plot, PointD, ChartImageOptions?)Draws a plot on a canvas, as vector shapes and text.
DrawChartScene(DrawingCanvas, ChartScene, PointD, ChartImageOptions?)Draws a scene on a canvas, as vector shapes and text.
MeasureChart(Plot, ChartImageOptions?)Measures the rectangle that ChartImageRenderer.DrawChart covers.
ToImage(ChartScene, ChartImageOptions?)Renders a scene as an image of its size times ChartImageOptions.Scale, rounded up.
ToImage(Plot, ChartImageOptions?)Renders a plot as an image of its size times ChartImageOptions.Scale, rounded up.

CreateMeasurer(ChartImageOptions?)

ChartImageRenderer.cs

Creates the text measurer of the fonts of the options, to lay a plot out with Plot.CreateScene.

public static ImageTextMeasurer CreateMeasurer(ChartImageOptions? options = null)

Parameters

options ChartImageOptions?
The options, or null for the defaults.

Returns

ImageTextMeasurer The measurer.

DrawChart(DrawingCanvas, Plot, PointD, ChartImageOptions?)

ChartImageRenderer.cs

Draws a plot on a canvas, as vector shapes and text.

public static RectangleD DrawChart(this DrawingCanvas canvas, Plot plot, PointD position, ChartImageOptions? options = null)

Parameters

canvas DrawingCanvas
The canvas.
plot Plot
The plot.
position PointD
The top-left corner of the chart.
options ChartImageOptions?
The options, or null for the defaults.

Returns

RectangleD The rectangle the chart covers.

Remarks

The chart is drawn in the coordinates of the canvas, so the transform, clip and layers of the canvas apply.

DrawChartScene(DrawingCanvas, ChartScene, PointD, ChartImageOptions?)

ChartImageRenderer.cs

Draws a scene on a canvas, as vector shapes and text.

public static RectangleD DrawChartScene(this DrawingCanvas canvas, ChartScene scene, PointD position, ChartImageOptions? options = null)

Parameters

canvas DrawingCanvas
The canvas.
scene ChartScene
The scene, laid out with ChartImageRenderer.CreateMeasurer so its texts fit.
position PointD
The top-left corner of the chart.
options ChartImageOptions?
The options, or null for the defaults.

Returns

RectangleD The rectangle the chart covers.

MeasureChart(Plot, ChartImageOptions?)

ChartImageRenderer.cs

Measures the rectangle that ChartImageRenderer.DrawChart covers.

public static RectangleD MeasureChart(Plot plot, ChartImageOptions? options = null)

Parameters

plot Plot
The plot.
options ChartImageOptions?
The options, or null for the defaults.

Returns

RectangleD The size of the drawing, as a rectangle located at the origin.

ToImage overloads

ToImage(ChartScene, ChartImageOptions?)

ChartImageRenderer.cs

Renders a scene as an image of its size times ChartImageOptions.Scale, rounded up.

public static Image<Rgba32> ToImage(this ChartScene scene, ChartImageOptions? options = null)
Parameters
scene ChartScene
The scene, laid out with ChartImageRenderer.CreateMeasurer so its texts fit.
options ChartImageOptions?
The options, or null for the defaults.
Returns

Image<Rgba32> A single-frame image. The caller owns it and must dispose it.

Exceptions
ArgumentOutOfRangeException
The image is too large.

ToImage(Plot, ChartImageOptions?)

ChartImageRenderer.cs

Renders a plot as an image of its size times ChartImageOptions.Scale, rounded up.

public static Image<Rgba32> ToImage(this Plot plot, ChartImageOptions? options = null)
Parameters
plot Plot
The plot.
options ChartImageOptions?
The options, or null for the defaults.
Returns

Image<Rgba32> A single-frame image. The caller owns it and must dispose it.