Skip to main content

DataLabelsOptions

Namespace: Wisej.Web.Ext.ChartJS4.Models

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

Represents the options of the chartjs-plugin-datalabels plugin (Chart.js options.plugins.datalabels), which draws labels next to or on top of the data elements.

public class DataLabelsOptions : OptionsBase

An instance is available through DataLabels. When it is serialized the client automatically registers the datalabels plugin; unless a formatter is specified through ExtensionData, the values are formatted by the ChartJS4 control. Labels are hidden by default: set Display to true to show them.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Display = true;
labels.Anchor = "end";
labels.Align = "top";
labels.Color = System.Drawing.Color.DarkBlue;
labels.Font.Size = 14;

Constructors​

Instance member DataLabelsOptions()​

Initializes a new instance of DataLabelsOptions.

Properties​

Instance member Align​

String: Returns or sets the position of the label relative to its anchor point (datalabels option align).

Value: One of "center", "start", "end", "left", "right", "top" or "bottom", or null (default) to use the plugin default ("center").

"start" and "end" are relative to the anchor point and follow the direction of the element (e.g. "end" places the label outside the top of a vertical bar when combined with Anchor"end"). Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Anchor = "end";
labels.Align = "top";

Instance member Anchor​

String: Returns or sets the anchor point of the label on the data element (datalabels option anchor).

Value: One of "center", "start" or "end", or null (default) to use the plugin default ("center").

"start" and "end" refer to the lowest and highest element boundaries (e.g. base and top of a bar). Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Display = true;
labels.Anchor = "end";

Instance member BackgroundColor​

Object: Returns or sets the background color of the label box (datalabels option backgroundColor).

Value: A Color, a CSS color string, or an array of colors (one per data point). The default is null (no background).

Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.BackgroundColor = "rgba(0, 0, 0, 0.6)";
labels.Color = System.Drawing.Color.White;

Instance member BorderColor​

Object: Returns or sets the border color of the label box (datalabels option borderColor).

Value: A Color, a CSS color string, or an array of colors. The default is null (no border color).

The border is drawn only when BorderWidth is greater than zero. Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.BorderWidth = 1;
labels.BorderColor = System.Drawing.Color.Gray;

Instance member BorderRadius​

Int32: Returns or sets the corner radius, in pixels, of the label box (datalabels option borderRadius). (Default: 0)

Value: The corner radius in pixels. The default is 0 (square corners).

Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.BackgroundColor = "#eeeeee";
labels.BorderRadius = 4;

Instance member BorderWidth​

Int32: Returns or sets the border width, in pixels, of the label box (datalabels option borderWidth). (Default: 0)

Value: The border width in pixels. The default is 0 (no border).

Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.BorderWidth = 2;
labels.BorderColor = "#336699";

Instance member Color​

Object: Returns or sets the text color of the labels (datalabels option color).

Value: A Color, a CSS color string, or an array of colors (one per data point). The default is null, which uses the Chart.js default font color.

Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Color = System.Drawing.Color.White;

Instance member Display​

Boolean: Returns or sets whether the data labels are displayed (datalabels option display). (Default: False)

Value: true to show the labels; otherwise false. The default is false.

This value is always serialized, so the labels are hidden unless the property is set to true. Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Display = true;

Instance member Font​

FontOptions: Returns or sets the font used to render the labels (datalabels option font).

Value: A FontOptions instance. The getter lazily creates a default instance on first access; the default is null (plugin default font).

Changing this property refreshes the chart.

Example:

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

Instance member Offset​

Int32: Returns or sets the distance, in pixels, used to pull the label away from its anchor point (datalabels option offset). (Default: 4)

Value: The offset in pixels. The default is 4.

The offset is applied in the direction defined by Align and has no effect when Align is "center". Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.Align = "end";
labels.Offset = 8;

Instance member Padding​

Int32: Returns or sets the padding, in pixels, applied inside the label box on all sides (datalabels option padding). (Default: 4)

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

Changing this property refreshes the chart.

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.BackgroundColor = "#ffffcc";
labels.Padding = 6;

Methods​

Protected member OnChartChanged()​

Called when the Chart reference changes.

Instance member ResetAlign()​

Resets the Align property to its default value.

Sets Align to null (plugin default). This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetAlign();

Instance member ResetAnchor()​

Resets the Anchor property to its default value.

Sets Anchor to null (plugin default). This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetAnchor();

Instance member ResetBackgroundColor()​

Resets the BackgroundColor property to its default value.

Sets BackgroundColor to null. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetBackgroundColor();

Instance member ResetBorderColor()​

Resets the BorderColor property to its default value.

Sets BorderColor to null. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetBorderColor();

Instance member ResetBorderRadius()​

Resets the BorderRadius property to its default value.

Sets BorderRadius to 0. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetBorderRadius();

Instance member ResetBorderWidth()​

Resets the BorderWidth property to its default value.

Sets BorderWidth to 0. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetBorderWidth();

Instance member ResetColor()​

Resets the Color property to its default value.

Sets Color to null. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetColor();

Instance member ResetDisplay()​

Resets the Display property to its default value.

Note that the current implementation sets Display to true, which differs from the declared default value (false). This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetDisplay();

Instance member ResetFont()​

Resets the Font property to its default value.

Sets Font to null; a new default instance is created on the next access. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetFont();

Instance member ResetOffset()​

Resets the Offset property to its default value.

Sets Offset to 4. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetOffset();

Instance member ResetPadding()​

Resets the Padding property to its default value.

Sets Padding to 4. This method is used by the Visual Studio designer and the property grid ("Reset" command).

Example:

var chart = new ChartJS4();
var labels = chart.ChartOptions.Plugins.DataLabels;
labels.ResetPadding();

Instance member ShouldSerializeAlign()​

Returns whether the Align property has been changed from its default value and should be serialized by the designer.

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

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeAlign())
labels.ResetAlign();

Instance member ShouldSerializeAnchor()​

Returns whether the Anchor property has been changed from its default value and should be serialized by the designer.

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

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeAnchor())
labels.ResetAnchor();

Instance member ShouldSerializeBackgroundColor()​

Returns whether the BackgroundColor property has been changed from its default value and should be serialized by the designer.

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

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeBackgroundColor())
labels.ResetBackgroundColor();

Instance member ShouldSerializeBorderColor()​

Returns whether the BorderColor property has been changed from its default value and should be serialized by the designer.

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

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeBorderColor())
labels.ResetBorderColor();

Instance member ShouldSerializeBorderRadius()​

Returns whether the BorderRadius property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if BorderRadius is not 0; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeBorderRadius())
labels.ResetBorderRadius();

Instance member ShouldSerializeBorderWidth()​

Returns whether the BorderWidth property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if BorderWidth is not 0; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeBorderWidth())
labels.ResetBorderWidth();

Instance member ShouldSerializeColor()​

Returns whether the Color property has been changed from its default value and should be serialized by the designer.

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

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeColor())
labels.ResetColor();

Instance member ShouldSerializeDisplay()​

Returns whether the Display property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if Display is not false; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeDisplay())
labels.ResetDisplay();

Instance member ShouldSerializeFont()​

Returns whether the Font property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if the font options have been created and at least one of their values differs from its default; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeFont())
labels.ResetFont();

Instance member ShouldSerializeOffset()​

Returns whether the Offset property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if Offset is not 4; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializeOffset())
labels.ResetOffset();

Instance member ShouldSerializePadding()​

Returns whether the Padding property has been changed from its default value and should be serialized by the designer.

Returns: Boolean. true if Padding is not 4; otherwise false.

This method is used by the Visual Studio designer and the property grid to determine whether the property value is persisted in the generated code.

Example:

if (labels.ShouldSerializePadding())
labels.ResetPadding();