Skip to main content

LegendLabelsOptions

Namespace: Wisej.Web.Ext.ChartJS4.Models

Assembly: Wisej.Web.Ext.ChartJS4 (4.1.0.0)

Represents the configuration of the legend labels (Chart.js options.plugins.legend.labels), which controls the colored boxes and text of each legend item.

public class LegendLabelsOptions : OptionsBase

An instance is created lazily by Labels. Changing any property updates the chart. Options that are not exposed as properties can be added through ExtensionData.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.Legend.Labels;
labels.UsePointStyle = true;
labels.Padding = 20;
labels.Font.Size = 14;

Constructors​

Instance member LegendLabelsOptions()​

Initializes a new instance of LegendLabelsOptions.

Properties​

Instance member BoxHeight​

Int32: Returns or sets the height, in pixels, of the colored box of each legend item (Chart.js boxHeight). (Default: 0)

Value: The height in pixels. The default is 0, which is not serialized, so Chart.js uses its default (the font size).

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.BoxWidth = 12;
chart.ChartOptions.Plugins.Legend.Labels.BoxHeight = 12;

Instance member BoxWidth​

Int32: Returns or sets the width, in pixels, of the colored box of each legend item (Chart.js boxWidth). (Default: 0)

Value: The width in pixels. The default is 0, which is not serialized, so Chart.js uses its default (40).

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.BoxWidth = 12;

Instance member Color​

Object: Returns or sets the color of the label text and of the strikethrough drawn on hidden datasets (Chart.js color).

Value: A Color or a CSS color string. The default is null, which uses the Chart.js default font color.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.Color = Color.DimGray;

Instance member Font​

FontOptions: Returns or sets the font configuration of the legend labels (Chart.js font).

Value: A FontOptions instance. The getter creates an empty instance on first access, so nested properties can be set directly.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.Font.Size = 14;
chart.ChartOptions.Plugins.Legend.Labels.Font.Weight = "bold";

Instance member Padding​

Int32: Returns or sets the padding, in pixels, between rows of colored boxes (Chart.js padding). (Default: 10)

Value: The padding in pixels. The default is 10.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.Padding = 20;

Instance member UsePointStyle​

Boolean: Returns or sets whether the legend items use the point style of the dataset rather than the default square (Chart.js usePointStyle). (Default: False)

Value: true to use the dataset point style; otherwise false. The default is false.

When true, the box size is derived from the font size and BoxWidth is ignored by Chart.js.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Labels.UsePointStyle = true;

Methods​

Protected member OnChartChanged()​

Called when the Chart reference changes.

Instance member ResetBoxHeight()​

Resets the BoxHeight property to its default value (0).

Used by the designer to restore the default value.

Example:

chart.ChartOptions.Plugins.Legend.Labels.ResetBoxHeight();

Instance member ResetBoxWidth()​

Resets the BoxWidth property to its default value (0).

Used by the designer to restore the default value.

Example:

chart.ChartOptions.Plugins.Legend.Labels.ResetBoxWidth();

Instance member ResetColor()​

Resets the Color property to its default value (null).

Used by the designer to restore the default value.

Example:

chart.ChartOptions.Plugins.Legend.Labels.ResetColor();

Instance member ResetFont()​

Resets the Font property to its default value by discarding the current FontOptions instance.

Used by the designer to restore the default value. A new, empty FontOptions is created the next time Font is read.

Example:

chart.ChartOptions.Plugins.Legend.Labels.ResetFont();

Instance member ResetPadding()​

Resets the Padding property to its default value (10).

Used by the designer to restore the default value.

Example:

chart.ChartOptions.Plugins.Legend.Labels.ResetPadding();

Instance member ShouldSerializeBoxHeight()​

Determines whether the BoxHeight property should be serialized by the designer.

Returns: Boolean. true if BoxHeight is not 0 (its default); otherwise false.

Used by the designer together with ResetBoxHeight.

Example:

var labels = chart.ChartOptions.Plugins.Legend.Labels;
if (labels.ShouldSerializeBoxHeight())
labels.ResetBoxHeight();

Instance member ShouldSerializeBoxWidth()​

Determines whether the BoxWidth property should be serialized by the designer.

Returns: Boolean. true if BoxWidth is not 0 (its default); otherwise false.

Used by the designer together with ResetBoxWidth.

Example:

var labels = chart.ChartOptions.Plugins.Legend.Labels;
if (labels.ShouldSerializeBoxWidth())
labels.ResetBoxWidth();

Instance member ShouldSerializeColor()​

Determines whether the Color property should be serialized by the designer.

Returns: Boolean. true if Color is not null; otherwise false.

Used by the designer together with ResetColor.

Example:

var labels = chart.ChartOptions.Plugins.Legend.Labels;
if (labels.ShouldSerializeColor())
labels.ResetColor();

Instance member ShouldSerializeFont()​

Determines whether the Font property should be serialized by the designer.

Returns: Boolean. true if Font is not null; otherwise false.

Used by the designer together with ResetFont. Because the Font getter creates an instance on demand, this method effectively always returns true.

Example:

var labels = chart.ChartOptions.Plugins.Legend.Labels;
if (labels.ShouldSerializeFont())
labels.ResetFont();

Instance member ShouldSerializePadding()​

Determines whether the Padding property should be serialized by the designer.

Returns: Boolean. true if Padding is not 10 (its default); otherwise false.

Used by the designer together with ResetPadding.

Example:

var labels = chart.ChartOptions.Plugins.Legend.Labels;
if (labels.ShouldSerializePadding())
labels.ResetPadding();