LegendOptions
Namespace: Wisej.Web.Ext.ChartJS4.Models
Assembly: Wisej.Web.Ext.ChartJS4 (4.1.0.0)
Represents the configuration of the Chart.js legend plugin (options.plugins.legend), which displays the datasets of the chart and lets the user toggle them.
- C#
- VB.NET
public class LegendOptions : OptionsBase
Public Class LegendOptions
Inherits OptionsBase
An instance is created lazily by Legend. Changing any property updates the chart. Options that are not exposed as properties can be added through ExtensionData.
Example:
var chart = new ChartJS4();
var legend = chart.ChartOptions.Plugins.Legend;
legend.Position = "bottom";
legend.Align = "start";
legend.Labels.UsePointStyle = true;
Constructors
LegendOptions()
Initializes a new instance of LegendOptions.
Properties
Align
String: Returns or sets the alignment of the legend within its box (Chart.js align).
Value: One of "start" | "center" | "end". The default is null, in which case Chart.js uses "center".
Example:
var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Align = "end";
Display
Boolean: Returns or sets whether the legend is shown (Chart.js display). (Default: True)
Value: true to show the legend; otherwise false. The default is true.
Example:
var chart = new ChartJS4();
bool legendVisible = chart.ChartOptions.Plugins.Legend.Display;
FullSize
Boolean: Returns or sets whether the legend box takes the full width (or height, when placed left or right) of the canvas, moving other boxes aside (Chart.js fullSize). (Default: True)
Value: true to take the full width/height of the canvas; otherwise false. The default is true.
Example:
var chart = new ChartJS4();
bool fullSize = chart.ChartOptions.Plugins.Legend.FullSize;
Labels
LegendLabelsOptions: Returns or sets the legend labels configuration (Chart.js labels).
Value: A LegendLabelsOptions 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.BoxWidth = 12;
chart.ChartOptions.Plugins.Legend.Labels.Color = Color.DarkGray;
MaxHeight
Int32: Returns or sets the maximum height of the legend, in pixels (Chart.js maxHeight).
Value: The maximum height in pixels. The default is 0, which is not serialized, so Chart.js applies no explicit limit.
Example:
var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.MaxHeight = 60;
MaxWidth
Int32: Returns or sets the maximum width of the legend, in pixels (Chart.js maxWidth).
Value: The maximum width in pixels. The default is 0, which is not serialized, so Chart.js applies no explicit limit.
Example:
var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Position = "right";
chart.ChartOptions.Plugins.Legend.MaxWidth = 150;
Position
String: Returns or sets the position of the legend (Chart.js position).
Value: One of "top" | "left" | "bottom" | "right" | "chartArea". The default is null, in which case Chart.js uses "top".
"chartArea" draws the legend inside the chart area instead of reserving space around it.
Example:
var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Position = "bottom";
Reverse
Boolean: Returns or sets whether the legend shows the datasets in reverse order (Chart.js reverse). (Default: False)
Value: true to reverse the order of the legend items; otherwise false. The default is false.
Example:
var chart = new ChartJS4();
chart.ChartOptions.Plugins.Legend.Reverse = true;
Title
LegendTitleOptions: Returns or sets the legend title configuration (Chart.js title).
Value: A LegendTitleOptions 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.Title.Display = true;
chart.ChartOptions.Plugins.Legend.Title.Text = "Regions";
Methods
OnChartChanged()
Called when the Chart reference changes.
ResetAlign()
Resets the Align property to its default value (null).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetAlign();
ResetDisplay()
Resets the Display property to its default value (true).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetDisplay();
ResetFullSize()
Resets the FullSize property to its default value (true).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetFullSize();
ResetLabels()
Resets the Labels property to its default value by discarding the current LegendLabelsOptions instance.
Used by the designer to restore the default value. A new, empty LegendLabelsOptions is created the next time Labels is read.
Example:
chart.ChartOptions.Plugins.Legend.ResetLabels();
ResetMaxHeight()
Resets the MaxHeight property to its default value (0).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetMaxHeight();
ResetMaxWidth()
Resets the MaxWidth property to its default value (0).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetMaxWidth();
ResetPosition()
Resets the Position property to its default value (null).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetPosition();
ResetReverse()
Resets the Reverse property to its default value (false).
Used by the designer to restore the default value.
Example:
chart.ChartOptions.Plugins.Legend.ResetReverse();
ResetTitle()
Resets the Title property to its default value by discarding the current LegendTitleOptions instance.
Used by the designer to restore the default value. A new, empty LegendTitleOptions is created the next time Title is read.
Example:
chart.ChartOptions.Plugins.Legend.ResetTitle();
ShouldSerializeAlign()
Determines whether the Align property should be serialized by the designer.
Returns: Boolean. true if Align is not null; otherwise false.
Used by the designer together with ResetAlign.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeAlign())
legend.ResetAlign();
ShouldSerializeDisplay()
Determines whether the Display property should be serialized by the designer.
Returns: Boolean. true if Display is not true (its default); otherwise false.
Used by the designer together with ResetDisplay.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeDisplay())
legend.ResetDisplay();
ShouldSerializeFullSize()
Determines whether the FullSize property should be serialized by the designer.
Returns: Boolean. true if FullSize is not true (its default); otherwise false.
Used by the designer together with ResetFullSize.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeFullSize())
legend.ResetFullSize();
ShouldSerializeLabels()
Determines whether the Labels property should be serialized by the designer.
Returns: Boolean. true if Labels is not null; otherwise false.
Used by the designer together with ResetLabels. Because the Labels getter creates an instance on demand, this method effectively always returns true.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeLabels())
legend.ResetLabels();
ShouldSerializeMaxHeight()
Determines whether the MaxHeight property should be serialized by the designer.
Returns: Boolean. true if MaxHeight is not 0 (its default); otherwise false.
Used by the designer together with ResetMaxHeight.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeMaxHeight())
legend.ResetMaxHeight();
ShouldSerializeMaxWidth()
Determines whether the MaxWidth property should be serialized by the designer.
Returns: Boolean. true if MaxWidth is not 0 (its default); otherwise false.
Used by the designer together with ResetMaxWidth.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeMaxWidth())
legend.ResetMaxWidth();
ShouldSerializePosition()
Determines whether the Position property should be serialized by the designer.
Returns: Boolean. true if Position is not null; otherwise false.
Used by the designer together with ResetPosition.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializePosition())
legend.ResetPosition();
ShouldSerializeReverse()
Determines whether the Reverse property should be serialized by the designer.
Returns: Boolean. true if Reverse is not false (its default); otherwise false.
Used by the designer together with ResetReverse.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeReverse())
legend.ResetReverse();
ShouldSerializeTitle()
Determines whether the Title property should be serialized by the designer.
Returns: Boolean. true if Title is not null; otherwise false.
Used by the designer together with ResetTitle. Because the Title getter creates an instance on demand, this method effectively always returns true.
Example:
var legend = chart.ChartOptions.Plugins.Legend;
if (legend.ShouldSerializeTitle())
legend.ResetTitle();