BarDataSet
Namespace: Wisej.Web.Ext.ChartJS4.Models
Assembly: Wisej.Web.Ext.ChartJS4 (4.1.0.0)
Data set for bar charts.
- C#
- VB.NET
public class BarDataSet : ChartDataSet
Public Class BarDataSet
Inherits ChartDataSet
Sets Type to "bar" and exposes bar-specific Chart.js options such as BarPercentage, CategoryPercentage, BorderRadius and BorderSkipped.
Example:
var chart = new ChartJS4 { ChartType = ChartType.Bar };
chart.Labels = new[] { "Q1", "Q2", "Q3", "Q4" };
chart.DataSets.Add(new BarDataSet
{
Label = "Revenue",
Data = new object[] { 40, 55, 48, 70 },
BackgroundColor = Color.SteelBlue,
BorderRadius = 6
});
Constructors
BarDataSet()
Initializes a new instance of the BarDataSet class.
Sets Type to "bar".
Example:
var bars = new BarDataSet();
bars.Label = "Orders";
bars.Data = new object[] { 12, 18, 9 };
chart.DataSets.Add(bars);
Properties
BarPercentage
Double: Returns or sets the percent (0-1) of the available width each bar should be within the category width. (Default: 0.9)
Value: A Double between 0 and 1. The default is 0.9. Maps to the Chart.js barPercentage option.
A value of 1.0 makes bars of the same category touch each other.
Example:
var bars = new BarDataSet { Label = "Sales" };
bars.BarPercentage = 1.0;
bars.CategoryPercentage = 1.0;
BorderRadius
Int32: Returns or sets the border radius of the bars. Set to a large number (e.g. MaxValue) for fully rounded bars. (Default: 0)
Value: An Int32 in pixels. The default is 0 (square corners). Maps to the Chart.js borderRadius option.
Use BorderSkipped to control which edge is not rounded.
Example:
var bars = new BarDataSet { Label = "Sales" };
bars.BorderRadius = int.MaxValue;
bars.BorderSkipped = false;
BorderSkipped
Object: Returns or sets which edge to skip border radius on. Set to false to apply border radius to all edges. Accepts 'start', 'end', 'left', 'right', 'top', 'bottom', or false.
Value: One of "start" | "end" | "middle" | "left" | "right" | "top" | "bottom", true, or false. The default is null (Chart.js default "start"). Maps to the Chart.js borderSkipped option.
Example:
var bars = new BarDataSet { Label = "Sales", BorderWidth = 2 };
bars.BorderSkipped = "bottom";
CategoryPercentage
Double: Returns or sets the percent (0-1) of the available width each category should be within the sample width. (Default: 0.8)
Value: A Double between 0 and 1. The default is 0.8. Maps to the Chart.js categoryPercentage option.
Example:
var bars = new BarDataSet { Label = "Sales" };
bars.CategoryPercentage = 0.6;
HoverBorderColor
Object: Returns or sets the border color of the bar when hovered.
Value: A Color, a CSS color string, or an array of colors (one per bar). The default is null (Chart.js default). Maps to the Chart.js hoverBorderColor option.
Example:
var bars = new BarDataSet { Label = "Sales" };
bars.HoverBorderColor = "rgba(0, 0, 0, 0.6)";
HoverBorderWidth
Int32: Returns or sets the border width of the bar when hovered. (Default: 1)
Value: An Int32 in pixels. The default is 1. Maps to the Chart.js hoverBorderWidth option.
Example:
var bars = new BarDataSet { Label = "Sales" };
bars.HoverBorderWidth = 3;
bars.HoverBorderColor = Color.Black;
Methods
ResetBarPercentage()
Resets the BarPercentage property to its default value of 0.9.
Used by the Visual Studio designer when the user resets the property.
Example:
bars.ResetBarPercentage();
ResetBorderRadius()
Resets the BorderRadius property to its default value of 0.
Used by the Visual Studio designer when the user resets the property.
Example:
bars.ResetBorderRadius();
ResetCategoryPercentage()
Resets the CategoryPercentage property to its default value of 0.8.
Used by the Visual Studio designer when the user resets the property.
Example:
bars.ResetCategoryPercentage();
ShouldSerializeBarPercentage()
Determines whether the BarPercentage property should be serialized by the designer.
Returns: Boolean. true if BarPercentage is not 0.9 (its default value); otherwise false.
Used by the Visual Studio designer to decide whether to generate code for the property.
Example:
if (bars.ShouldSerializeBarPercentage())
bars.ResetBarPercentage();
ShouldSerializeBorderRadius()
Determines whether the BorderRadius property should be serialized by the designer.
Returns: Boolean. true if BorderRadius is not 0 (its default value); otherwise false.
Used by the Visual Studio designer to decide whether to generate code for the property.
Example:
if (bars.ShouldSerializeBorderRadius())
bars.ResetBorderRadius();
ShouldSerializeCategoryPercentage()
Determines whether the CategoryPercentage property should be serialized by the designer.
Returns: Boolean. true if CategoryPercentage is not 0.8 (its default value); otherwise false.
Used by the Visual Studio designer to decide whether to generate code for the property.
Example:
if (bars.ShouldSerializeCategoryPercentage())
bars.ResetCategoryPercentage();