OptionsLegend
Namespace: Wisej.Web.Ext.ChartJS3
Assembly: Wisej.Web.Ext.ChartJS3 (4.1.0.0)
Represents the options for the chart legend.
- C#
- VB.NET
public class OptionsLegend : OptionsBase
Public Class OptionsLegend
Inherits OptionsBase
An instance of this class is exposed by the Legend property and maps to the plugins.legend configuration of Chart.js 3.
Example:
var legend = this.chartJS31.Options.Plugins.Legend;
legend.Position = HeaderPosition.Bottom;
legend.Labels.UsePointStyle = true;
legend.Labels.Padding = 20;
Constructors
OptionsLegend()
Default constructor.
Creates a set of legend options that is not attached to an owner.
Example:
var legend = new OptionsLegend();
legend.Position = HeaderPosition.Right;
this.chartJS31.Options.Plugins.Legend = legend;
this.chartJS31.Update();
OptionsLegend(owner)
Constructs a new instance of the OptionsLegend set.
| Name | Type | Description |
|---|---|---|
| owner | OptionsBase | The OptionsBase instance (usually the OptionsPlugins) that owns this set of options. |
Example:
var plugins = this.chartJS31.Options.Plugins;
var legend = new OptionsLegend(plugins);
legend.Display = false;
plugins.Legend = legend;
Properties
Display
Boolean: Returns or sets whether the legend is displayed. (Default: True)
Value: The default is true.
Setting this property calls Update to refresh the chart.
Example:
// a chart with a single data set doesn't need a legend.
this.chartJS31.Options.Plugins.Legend.Display = this.chartJS31.DataSets.Count > 1;
Labels
OptionsLegendLabels: Returns or sets the options for the labels in the legend.
Value: An OptionsLegendLabels instance; it's created automatically on first access.
Maps to the plugins.legend.labels option of Chart.js 3.
Throws:
- ArgumentNullException The value is null.
- InvalidOperationException The OptionsLegendLabels instance already belongs to another set of options.
Example:
var labels = this.chartJS31.Options.Plugins.Legend.Labels;
labels.BoxWidth = 20;
labels.Color = Color.DimGray;
labels.Font = new Font("Segoe UI", 10F);
Position
HeaderPosition: Returns or sets the position of the legend. (Default: Top)
Value: One of the HeaderPosition values. The default is Top.
Setting this property calls Update to refresh the chart.
Example:
// show the legend to the right of a pie chart.
this.chartJS31.ChartType = ChartType.Pie;
this.chartJS31.Options.Plugins.Legend.Position = HeaderPosition.Right;