Skip to main content

ChartOptions

Namespace: Wisej.Web.Ext.ChartJS4.Models

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

Base class for all chart options. Uses System.Text.Json for modern, flexible serialization.

public class ChartOptions : ChartModelBase

An instance is exposed by ChartOptions and serialized to the Chart.js options object. Nested option objects (Plugins, Scales, Interaction, Transitions, Layout) are created lazily on first access, and only non-default values are sent to the client. Changing any property refreshes the owning chart. Options not exposed as properties can be supplied through ExtensionData or CustomOptions.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Title.Display = true;
chart.ChartOptions.Plugins.Title.Text = "Monthly Sales";
chart.ChartOptions.Plugins.Legend.Position = "bottom";
chart.ChartOptions.Scales.Y.Min = 0;

Constructors​

Instance member ChartOptions()​

Initializes a new instance of the ChartOptions class.

Nested option objects are not created by the constructor; they are instantiated lazily the first time the corresponding property is read.

Example:

var options = new ChartOptions { Responsive = true, AspectRatio = 1 };
chart.ChartOptions = options;

Properties​

Instance member Animation​

Object: Returns or sets the global animation configuration. Accepts an object or anonymous type with Chart.js animation properties (e.g., new { duration = 1000, easing = "linear" }). Different from Animations which configures per-property animations. (Default: null)

Value: An object with Chart.js animation properties (duration, easing, delay, loop), an AnimationsOptions instance, false to disable all animations, or null. The default is null (Chart.js defaults). Maps to the Chart.js animation option.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Animation = new AnimationsOptions { Duration = 500, Easing = "easeInOutQuart" };

// Disable animations:
chart.ChartOptions.Animation = false;

Instance member Animations​

Object: Returns or sets the per-property animation configurations used when data changes. Accepts an AnimationsOptions instance or an anonymous object. (Default: null)

Value: An AnimationsOptions instance, an anonymous object whose properties are animation names (e.g. x, y, colors, numbers) with Chart.js animation configurations as values, or null. The default is null. Serialized as the Chart.js animations option through AnimationsForSerialization.

Unlike the other nested options, this property is not created lazily. For a single global animation configuration use Animation instead.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Animations = new
{
y = new { duration = 2000, easing = "easeOutBounce" }
};

Instance member AspectRatio​

Nullable<Int32>: Returns or sets the canvas aspect ratio (i.e., width / height, a value of 1 representing a square canvas). (Default: 2)

Value: A nullable Int32. The default is 2. Maps to the Chart.js aspectRatio option.

Only applies when MaintainAspectRatio is true.

Example:

var chart = new ChartJS4();
chart.ChartOptions.AspectRatio = 1; // square chart

Instance member DevicePixelRatio​

Nullable<Double>: Returns or sets a value that overrides the window's default devicePixelRatio. (Default: null)

Value: A nullable Double. The default is null (use the browser's window.devicePixelRatio). Maps to the Chart.js devicePixelRatio option.

Setting a higher value renders the canvas at a higher resolution, e.g. to obtain sharper images from GetImageAsync or when printing.

Example:

var chart = new ChartJS4();
chart.ChartOptions.DevicePixelRatio = 2.0;

Instance member Elements​

Object: Returns or sets the default configuration of the chart elements (points, lines, bars and arcs). Accepts an ElementsOptions instance or an anonymous object. (Default: null)

Value: An ElementsOptions instance, an anonymous object with point, line, bar and/or arc members, or null. The default is null. Serialized as the Chart.js elements option through ElementsForSerialization.

Unlike the other nested options, this property is not created lazily. Element options apply to all datasets unless overridden by the dataset properties.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Elements = new
{
line = new { tension = 0.3 },
point = new { radius = 0 }
};

Instance member Interaction​

InteractionOptions: Returns or sets the interaction options that control how the chart reacts to mouse and touch events. (Default: null)

Value: An InteractionOptions instance. The getter never returns null: a new instance is created on first access. Serialized as the Chart.js interaction option through InteractionForSerialization.

These settings are shared by hover and tooltip interactions.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Interaction.Mode = "index";
chart.ChartOptions.Interaction.Intersect = false;

Instance member Layout​

LayoutOptions: Returns or sets the layout configuration (padding around the chart area). (Default: null)

Value: A LayoutOptions instance. The getter never returns null: a new instance is created on first access. Serialized as the Chart.js layout option through LayoutForSerialization.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Layout.Padding.Top = 20;
chart.ChartOptions.Layout.Padding.Bottom = 10;

Instance member Locale​

String: Returns or sets the chart's locale. Defaults to browser's locale. (Default: null)

Value: A BCP 47 language tag such as "en-US" or "de-DE". The default is null (browser locale). Maps to the Chart.js locale option.

The locale is used by Chart.js to format numbers (e.g. tick labels and tooltips).

Example:

var chart = new ChartJS4();
chart.ChartOptions.Locale = "de-DE";

Instance member MaintainAspectRatio​

Boolean: Returns or sets whether the original canvas aspect ratio (width / height) is maintained when resizing. (Default: True)

Value: true to keep the aspect ratio defined by AspectRatio; false to fill the container. The default is true. Maps to the Chart.js maintainAspectRatio option.

A value of false lets the chart fill the whole client area of the control. Note that false is currently not sent to the client, because default values are omitted during serialization, so Chart.js keeps its default of true.

Example:

var chart = new ChartJS4 { Dock = DockStyle.Fill };
bool keepRatio = chart.ChartOptions.MaintainAspectRatio;

Instance member Plugins​

PluginsOptions: Returns or sets the plugins options (legend, title, subtitle, tooltip, decimation, filler and data labels). (Default: null)

Value: A PluginsOptions instance. The getter never returns null: a new instance is created on first access. Serialized as the Chart.js plugins option through PluginsForSerialization.

Because the object is created lazily, nested options can be set directly, e.g. chart.ChartOptions.Plugins.Legend.Position = "bottom".

Example:

var chart = new ChartJS4();
chart.ChartOptions.Plugins.Title.Display = true;
chart.ChartOptions.Plugins.Title.Text = "Quarterly Revenue";
chart.ChartOptions.Plugins.Legend.Position = "bottom";

Instance member ResizeDelay​

Nullable<Int32>: Returns or sets the delay, in milliseconds, of the resize update. (Default: 0)

Value: A nullable Int32 in milliseconds. The default is null (Chart.js default 0, resize immediately). Maps to the Chart.js resizeDelay option.

Delaying the resize can improve performance when the container is resized frequently.

Example:

var chart = new ChartJS4();
chart.ChartOptions.ResizeDelay = 200;

Instance member Responsive​

Boolean: Returns or sets whether the chart canvas is resized when its container is. (Default: True)

Value: true to resize the canvas with its container; otherwise false. The default is true. Maps to the Chart.js responsive option.

Example:

var chart = new ChartJS4();
bool responsive = chart.ChartOptions.Responsive;

Instance member Scales​

ScalesOptions: Returns or sets the scales (axes) options. (Default: null)

Value: A ScalesOptions instance. The getter never returns null: a new instance is created on first access. Serialized as the Chart.js scales option through ScalesForSerialization.

Configures the x and y axes of cartesian charts; additional axes can be added through ExtensionData.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Scales.Y.Min = 0;
chart.ChartOptions.Scales.Y.Max = 100;
chart.ChartOptions.Scales.X.Title.Display = true;
chart.ChartOptions.Scales.X.Title.Text = "Month";

Instance member Transitions​

TransitionsOptions: Returns or sets the transitions configuration, i.e. the animations applied for specific modes such as active, resize, show and hide. (Default: null)

Value: A TransitionsOptions instance. The getter never returns null: a new instance is created on first access. Serialized as the Chart.js transitions option through TransitionsForSerialization.

The transition modes are supplied through ExtensionData.

Example:

var chart = new ChartJS4();
chart.ChartOptions.Transitions.ExtensionData = new Dictionary<string, object>
{
["active"] = new { animation = new { duration = 400 } }
};

Instance member Type​

String: Returns or sets a string that overrides the chart type (e.g., "customBubble") used in the top-level Chart.js config. Not serialized into the options object; consumed directly by the widget. (Default: null)

Value: A Chart.js chart type name, or null. The default is null, in which case the lower-cased ChartType is used.

Use this property to select a custom chart type (controller) registered on the client, or a built-in type name not covered by the ChartType enumeration.

Example:

var chart = new ChartJS4 { ChartType = ChartType.Custom };
chart.ChartOptions.Type = "customBubble";

Methods​

Protected member OnChartChanged()​

Called when the Chart reference changes.

Instance member ResetAnimation()​

Resets the Animation property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetAnimation();

Instance member ResetAnimations()​

Resets the Animations property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetAnimations();

Instance member ResetAspectRatio()​

Resets the AspectRatio property to its default value of 2.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetAspectRatio();

Instance member ResetDevicePixelRatio()​

Resets the DevicePixelRatio property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetDevicePixelRatio();

Instance member ResetElements()​

Resets the Elements property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetElements();

Instance member ResetInteraction()​

Resets the Interaction property by discarding the current interaction options.

A new default InteractionOptions instance is created on the next access to Interaction. Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetInteraction();

Instance member ResetLayout()​

Resets the Layout property by discarding the current layout options.

A new default LayoutOptions instance is created on the next access to Layout. Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetLayout();

Instance member ResetLocale()​

Resets the Locale property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetLocale();

Instance member ResetMaintainAspectRatio()​

Resets the MaintainAspectRatio property to its default value of true.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetMaintainAspectRatio();

Instance member ResetPlugins()​

Resets the Plugins property by discarding the current plugins options.

A new default PluginsOptions instance is created on the next access to Plugins. Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetPlugins();

Instance member ResetResizeDelay()​

Resets the ResizeDelay property to its default value of null.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetResizeDelay();

Instance member ResetResponsive()​

Resets the Responsive property to its default value of true.

Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetResponsive();

Instance member ResetScales()​

Resets the Scales property by discarding the current scales options.

A new default ScalesOptions instance is created on the next access to Scales. Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetScales();

Instance member ResetTransitions()​

Resets the Transitions property by discarding the current transitions options.

A new default TransitionsOptions instance is created on the next access to Transitions. Used by the Visual Studio designer when the user resets the property.

Example:

chart.ChartOptions.ResetTransitions();

Instance member ShouldSerializeAnimation()​

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

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

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeAnimation())
options.ResetAnimation();

Instance member ShouldSerializeAnimations()​

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

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

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeAnimations())
options.ResetAnimations();

Instance member ShouldSerializeAspectRatio()​

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

Returns: Boolean. true if AspectRatio is not 2 (its default value); otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeAspectRatio())
options.ResetAspectRatio();

Instance member ShouldSerializeDevicePixelRatio()​

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

Returns: Boolean. true if DevicePixelRatio has a value; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeDevicePixelRatio())
options.ResetDevicePixelRatio();

Instance member ShouldSerializeElements()​

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

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

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeElements())
options.ResetElements();

Instance member ShouldSerializeInteraction()​

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

Returns: Boolean. true if the interaction options were created and contain non-default values; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property. Does not create the lazy instance.

Example:

if (options.ShouldSerializeInteraction())
options.ResetInteraction();

Instance member ShouldSerializeLayout()​

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

Returns: Boolean. true if the layout options were created and contain non-default values; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property. Does not create the lazy instance.

Example:

if (options.ShouldSerializeLayout())
options.ResetLayout();

Instance member ShouldSerializeLocale()​

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

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

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeLocale())
options.ResetLocale();

Instance member ShouldSerializeMaintainAspectRatio()​

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

Returns: Boolean. true if MaintainAspectRatio is not true (its default value); otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeMaintainAspectRatio())
options.ResetMaintainAspectRatio();

Instance member ShouldSerializePlugins()​

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

Returns: Boolean. true if the plugins options were created and contain non-default values; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property. Does not create the lazy instance.

Example:

if (options.ShouldSerializePlugins())
options.ResetPlugins();

Instance member ShouldSerializeResizeDelay()​

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

Returns: Boolean. true if ResizeDelay has a value other than 0; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeResizeDelay())
options.ResetResizeDelay();

Instance member ShouldSerializeResponsive()​

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

Returns: Boolean. true if Responsive is not true (its default value); otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property.

Example:

if (options.ShouldSerializeResponsive())
options.ResetResponsive();

Instance member ShouldSerializeScales()​

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

Returns: Boolean. true if the scales options were created and contain non-default values; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property. Does not create the lazy instance.

Example:

if (options.ShouldSerializeScales())
options.ResetScales();

Instance member ShouldSerializeTransitions()​

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

Returns: Boolean. true if the transitions options were created and contain non-default values; otherwise false.

Used by the Visual Studio designer to decide whether to generate code for the property. Does not create the lazy instance.

Example:

if (options.ShouldSerializeTransitions())
options.ResetTransitions();