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.
- C#
- VB.NET
public class LegendLabelsOptions : OptionsBase
Public Class LegendLabelsOptions
Inherits 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
LegendLabelsOptions()
Initializes a new instance of LegendLabelsOptions.
Properties
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;
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;
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;
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";
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;
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
OnChartChanged()
Called when the Chart reference changes.
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();