# Chart
## Description
A native Blazor charting component rendered entirely with SVG. The API closely mirrors Chart.js: configure it with a BitChartType plus BitChartData and BitChartOptions (or a single BitChartConfig). It supports line, bar, area, pie, doughnut, polar area, radar, scatter, bubble and mixed charts, with scales, legends, tooltips, annotations, animations, scriptable options and zoom/pan.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Config | `BitChartConfig?` | null | Full configuration (type + data + options). Takes precedence over Type/Data/Options when set. |
| Type | `BitChartType` | BitChartType.Line | The chart type: Line, Bar, Radar, Pie, Doughnut, PolarArea, Bubble or Scatter. |
| Data | `BitChartData?` | null | The chart data: labels and datasets. |
| Options | `BitChartOptions?` | null | The chart options: scales, plugins (title, legend, tooltip), interaction, animation and zoom. |
| Width | `string` | 100% | CSS width of the chart container. |
| Height | `string?` | null | Optional CSS height of the chart container. When null the height follows the aspect ratio. |
| Class | `string?` | null | Custom CSS class applied to the root element of the chart. |
| Style | `string?` | null | Custom CSS style applied to the root element of the chart. |
| AriaLabel | `string?` | null | Accessible label for the chart. When null a summary is generated from the title and datasets. |
| GenerateTable | `bool` | true | Renders a visually-hidden data table for screen readers. |
| RespectReducedMotion | `bool` | true | When true, animations are disabled for users who requested reduced motion (prefers-reduced-motion: reduce). Set to false to always animate regardless of the OS setting. |
| TooltipTemplate | `RenderFragment<BitChartTooltipContext>?` | null | Optional custom tooltip template. When set it replaces the default tooltip body. |
| OnElementClick | `EventCallback<(int DatasetIndex, int DataIndex)>` | | Callback raised when a data element (point, bar, arc, ...) is clicked. |
## Sub Classes
### BitChartConfig Properties
A complete chart configuration bundling the type, data and options.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Type | `BitChartType` | BitChartType.Line | The chart type. |
| Data | `BitChartData` | new() | The labels and datasets. |
| Options | `BitChartOptions` | new() | The scales, plugins, interaction, animation and zoom options. |
### BitChartData Properties
The chart data, mirroring Chart.js data: labels + datasets.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Labels | `List<string>` | new() | The category labels shared by the datasets (used by cartesian, radar, pie and polar charts). |
| Datasets | `List<BitChartDataset>` | new() | The datasets to render. Each dataset carries either a list of values (Data) or points (Points). |
### BitChartDataset Properties
A single dataset, mirroring Chart.js dataset configuration.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Label | `string?` | null | Dataset label shown in legends and tooltips. |
| Data | `List<double?>` | new() | Per-index values (line, bar, radar, pie, doughnut, polarArea). |
| Points | `List<BitChartDataPoint>?` | null | Point data (x, y[, r]) for scatter/bubble charts. When set, takes precedence over Data. |
| Type | `BitChartType?` | null | Optional per-dataset type override, used to build mixed charts. |
| BackgroundColor | `string?` | null | The fill color of the dataset (bars, arcs, points and area fills). |
| BorderColor | `string?` | null | The line/border color of the dataset. |
| Fill | `BitChartFillMode` | BitChartFillMode.None | Area fill mode for line/radar datasets (None, Origin, Start, End, Stack, Dataset, Value). |
| Tension | `double` | 0 | Bezier curve tension for line datasets (0 = straight lines). |
## Examples
\n**Smooth line with area fill**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Filled() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Visitors", Data = new() { 120, 190, 160, 250, 220, 300, 280 },
BorderColor = "#36a2eb", Tension = 0.4, Fill = BitChartFillMode.Origin }
}
};
```
\n**Dashed border with custom points**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Dashed() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Forecast", Data = new() { 30, 42, null, 55, 48, 67, 70 },
BorderColor = "#9966ff", BorderDash = new() { 6, 4 }, PointStyle = BitChartPointStyle.Star,
PointRadius = 6, SpanGaps = true }
}
};
```
\n**Logarithmic Y axis**:
```razor
```
```csharp
private readonly BitChartOptions _logOptions = new()
{
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Logarithmic } }
};
private BitChartData Log() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Growth", Data = new() { 1, 10, 100, 1000, 5000, 20000, 80000 },
BorderColor = "#ff6384", Tension = 0.2 }
}
};
```
\n**Per-segment styling**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Segmented() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset
{
Label = "Flow",
Data = new() { 40, 55, 48, 70, 62, 80, 72 },
BorderColor = "#36a2eb",
BorderWidth = 3,
Segment = new BitChartLineSegmentStyle
{
BorderColor = ctx => ctx.EndValue < ctx.StartValue ? "#ff6384" : "#2ecc71",
BorderDash = ctx => ctx.StartIndex >= 4 ? new double[] { 6, 4 } : null
}
}
}
};
```
\n**Grouped**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Revenue() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Product A", Data = new() { 12, 19, 14, 22, 18, 25, 20 }, BackgroundColor = "#36a2eb" },
new BitChartDataset { Label = "Product B", Data = new() { 8, 11, 17, 9, 14, 12, 19 }, BackgroundColor = "#ff9f40" },
new BitChartDataset { Label = "Product C", Data = new() { 5, 7, 9, 12, 8, 10, 14 }, BackgroundColor = "#4bc0c0" }
}
};
```
\n**Stacked**:
```razor
```
```csharp
private readonly BitChartOptions _stacked = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Category, Stacked = true },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Stacked = true, BeginAtZero = true }
}
};
// Revenue() returns 3 datasets (Product A/B/C) over Jan..Jul.
```
\n**Horizontal**:
```razor
```
```csharp
private readonly BitChartOptions _horizontal = new()
{
IndexAxis = BitChartIndexAxis.Y,
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private BitChartData PerColor() => new()
{
Labels = { "Red", "Blue", "Teal", "Orange", "Purple" },
Datasets =
{
new BitChartDataset
{
Label = "Votes",
Data = new() { 12, 19, 7, 15, 9 },
BackgroundColors = new() { "#ff6384", "#36a2eb", "#4bc0c0", "#ff9f40", "#9966ff" },
BorderRadius = 6
}
}
};
```
\n**Floating bars**:
```razor
```
```csharp
private readonly BitChartOptions _noLegend = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private BitChartData Floating() => new()
{
Labels = { "Mon", "Tue", "Wed", "Thu", "Fri" },
Datasets =
{
new BitChartDataset
{
Label = "Temp range (°C)",
BackgroundColor = "#ff9f40",
BorderRadius = 4,
RangeData = new() { (8, 16), (10, 19), (7, 14), (11, 21), (9, 18) }
}
}
};
```
\n**100% stacked**:
```razor
```
```csharp
private readonly BitChartOptions _stacked100 = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Category, Stacked = true },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Stacked = true, Stacked100 = true,
Ticks = new BitChartTickOptions { Suffix = "%" } }
}
};
// Revenue() returns 3 datasets (Product A/B/C) over Jan..Jul.
```
\n**Pattern fills**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Patterned() => new()
{
Labels = { "Alpha", "Beta", "Gamma", "Delta" },
Datasets =
{
new BitChartDataset { Label = "A", Data = new() { 40, 55, 35, 60 }, BorderColor = "#36a2eb", BorderWidth = 1,
BackgroundPattern = new BitChartFillPattern(BitChartPatternStyle.DiagonalUp, "#36a2eb", "rgba(54,162,235,0.12)") },
new BitChartDataset { Label = "B", Data = new() { 28, 42, 50, 33 }, BorderColor = "#ff6384", BorderWidth = 1,
BackgroundPattern = new BitChartFillPattern(BitChartPatternStyle.Dots, "#ff6384", "rgba(255,99,132,0.10)") }
}
};
```
\n**Stacked groups**:
```razor
```
```csharp
private readonly BitChartOptions _stackedGroups = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Category, Stacked = true },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Stacked = true, BeginAtZero = true }
}
};
private BitChartData StackedGroups() => new()
{
Labels = { "Q1", "Q2", "Q3", "Q4" },
Datasets =
{
new BitChartDataset { Label = "2025 · New", Stack = "2025", Data = new() { 20, 28, 24, 32 }, BackgroundColor = "#36a2eb" },
new BitChartDataset { Label = "2025 · Renew", Stack = "2025", Data = new() { 12, 16, 14, 18 }, BackgroundColor = "#9cd0f5" },
new BitChartDataset { Label = "2026 · New", Stack = "2026", Data = new() { 26, 30, 29, 38 }, BackgroundColor = "#ff6384" },
new BitChartDataset { Label = "2026 · Renew", Stack = "2026", Data = new() { 15, 18, 17, 22 }, BackgroundColor = "#ffb1c1" }
}
};
```
\n**Stacked area**:
```razor
```
```csharp
private readonly BitChartOptions _stacked = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Category },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Stacked = true, BeginAtZero = true }
}
};
private BitChartData Stacked() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Organic", Data = new() { 30, 40, 35, 50, 45, 60, 55 }, BorderColor = "#36a2eb", Fill = BitChartFillMode.Stack },
new BitChartDataset { Label = "Paid", Data = new() { 20, 25, 30, 28, 35, 30, 40 }, BorderColor = "#ff6384", Fill = BitChartFillMode.Stack },
new BitChartDataset { Label = "Referral", Data = new() { 10, 12, 15, 18, 14, 20, 22 }, BorderColor = "#4bc0c0", Fill = BitChartFillMode.Stack }
}
};
```
\n**Range (fill between datasets)**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Range() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Max", Data = new() { 28, 32, 30, 36, 40, 44, 42 }, BorderColor = "#ff9f40",
Fill = BitChartFillMode.Dataset, FillTargetIndex = 1, FillColor = "rgba(255,159,64,0.18)" },
new BitChartDataset { Label = "Min", Data = new() { 14, 16, 15, 20, 24, 26, 23 }, BorderColor = "#36a2eb",
Fill = BitChartFillMode.None }
}
};
```
\n**Fill boundaries**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Boundaries() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Origin", Data = new() { 10, -20, 30, -10, 25, -5, 15 }, BorderColor = "#36a2eb",
Fill = BitChartFillMode.Origin, FillColor = "rgba(54,162,235,0.15)", Tension = 0.3 },
new BitChartDataset { Label = "Start (top)", Data = new() { 40, 35, 45, 38, 50, 44, 55 }, BorderColor = "#ff6384",
Fill = BitChartFillMode.Start, FillColor = "rgba(255,99,132,0.12)", Tension = 0.3 }
}
};
```
\n**Pie**:
```razor
```
```csharp
private readonly BitChartOptions _right = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Right } }
};
private BitChartData Traffic() => new()
{
Labels = { "Direct", "Organic", "Referral", "Social", "Email" },
Datasets =
{
new BitChartDataset { Label = "Sessions", Data = new() { 300, 500, 180, 240, 120 } }
}
};
```
\n**Half doughnut (gauge)**:
```razor
```
```csharp
private readonly BitChartOptions _gauge = new()
{
CutoutPercentage = 65,
CircumferenceDegrees = 180,
RotationDegrees = -90,
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Gauge() => new()
{
Labels = { "Used", "Free" },
Datasets =
{
new BitChartDataset { Data = new() { 68, 32 }, BackgroundColors = new() { "#ff6384", "#e6e9ef" } }
}
};
```
\n**Multi-ring**:
```razor
```
```csharp
private readonly BitChartOptions _right = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Right } }
};
private BitChartData MultiRing() => new()
{
Labels = { "Mobile", "Desktop", "Tablet" },
Datasets =
{
new BitChartDataset { Label = "2025", Data = new() { 55, 35, 10 } },
new BitChartDataset { Label = "2026", Data = new() { 62, 28, 10 } }
}
};
```
\n**Center text (KPI)**:
```razor
```
```csharp
private readonly BitChartOptions _centerText = new()
{
CutoutPercentage = 68,
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Right },
Custom = { new BitChartCenterTextPlugin("1,340", "sessions") }
}
};
// Traffic(): Direct/Organic/Referral/Social/Email = 300/500/180/240/120
```
\n**Polar area**:
```razor
```
```csharp
private readonly BitChartOptions _right = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Right } }
};
private BitChartData Data() => new()
{
Labels = { "Red", "Green", "Yellow", "Grey", "Blue" },
Datasets =
{
new BitChartDataset { Label = "Votes", Data = new() { 11, 16, 7, 14, 20 } }
}
};
```
\n**Centered point labels**:
```razor
```
```csharp
private readonly BitChartOptions _labels = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales =
{
["r"] = new BitChartScaleOptions
{
Id = "r", Type = BitChartScaleType.RadialLinear,
PointLabels = new BitChartPointLabelOptions { Color = "#36507a", Font = new BitChartFont { Size = 12, Weight = "bold" } }
}
}
};
private BitChartData Data() => new()
{
Labels = { "Red", "Green", "Yellow", "Grey", "Blue" },
Datasets =
{
new BitChartDataset { Label = "Votes", Data = new() { 11, 16, 7, 14, 20 } }
}
};
```
\n**Two players**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
private BitChartData Skills() => new()
{
Labels = { "Speed", "Power", "Range", "Defense", "Agility", "Stamina" },
Datasets =
{
new BitChartDataset { Label = "Player 1", Data = new() { 80, 65, 70, 60, 85, 75 },
BorderColor = "#36a2eb", Fill = BitChartFillMode.Origin },
new BitChartDataset { Label = "Player 2", Data = new() { 55, 80, 60, 90, 50, 65 },
BorderColor = "#ff6384", Fill = BitChartFillMode.Origin }
}
};
```
\n**Circular grid**:
```razor
```
```csharp
private readonly BitChartOptions _circular = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["r"] = new BitChartScaleOptions
{
Id = "r", Type = BitChartScaleType.RadialLinear, BeginAtZero = true,
Grid = new BitChartGridOptions { Circular = true },
AngleLineColor = "rgba(0,0,0,0.15)",
PointLabels = new BitChartPointLabelOptions { Color = "#36a2eb", Font = new BitChartFont { Size = 12, Weight = "bold" } }
}
}
};
// Skills(): Speed/Power/Range/Defense/Agility/Stamina for Player 1 & 2
```
\n**Skipped points**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
// null values are skipped, not treated as zero
private BitChartData Skip() => new()
{
Labels = { "Speed", "Power", "Range", "Defense", "Agility", "Stamina" },
Datasets =
{
new BitChartDataset { Label = "Scouted", Data = new() { 80, 65, null, 60, 85, null },
BorderColor = "#9966ff", Fill = BitChartFillMode.Origin }
}
};
```
\n**Scatter**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom, Labels = new BitChartLegendLabelOptions { UsePointStyle = true } }
},
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Linear, Grace = 0.1 },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Grace = 0.1 }
}
};
private BitChartData ScatterData() => new()
{
Datasets =
{
new BitChartDataset
{
Label = "Group A", BackgroundColor = "#36a2eb",
Points = new()
{
new(-8, 5), new(-5, 8), new(-3, 2), new(-1, 6), new(0, 9),
new(2, 4), new(4, 11), new(6, 7), new(9, 13)
}
},
new BitChartDataset
{
Label = "Group B", BackgroundColor = "#ff6384", PointStyle = BitChartPointStyle.Triangle, PointRadius = 5,
Points = new()
{
new(-7, -3), new(-4, -1), new(-2, -6), new(1, -2), new(3, -7),
new(5, -1), new(7, -5), new(10, 0)
}
}
}
};
```
\n**Bubble**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom, Labels = new BitChartLegendLabelOptions { UsePointStyle = true } }
},
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Linear, Grace = 0.1 },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Grace = 0.1 }
}
};
private BitChartData BubbleData() => new()
{
Datasets =
{
new BitChartDataset
{
Label = "Markets",
BackgroundColor = BitChartColorUtil.WithAlpha("#4bc0c0", 0.5),
BorderColor = "#4bc0c0",
// BitChartDataPoint(x, y, r) - r drives the bubble radius
Points = new()
{
new(10, 20, 14), new(15, 10, 8), new(20, 30, 22),
new(25, 18, 10), new(30, 25, 30), new(35, 12, 6)
}
}
}
};
```
\n**Bar + line**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } }
};
// Each dataset sets its own Type to mix bars and lines.
private BitChartData BarLine() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Type = BitChartType.Bar, Label = "Units", Data = new() { 40, 55, 48, 70, 62, 80, 75 }, BackgroundColor = "#36a2eb" },
new BitChartDataset { Type = BitChartType.Line, Label = "Trend", Data = new() { 38, 50, 52, 64, 68, 76, 80 }, BorderColor = "#ff6384", Tension = 0.4 }
}
};
```
\n**Dual axis**:
```razor
```
```csharp
private readonly BitChartOptions _dual = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Position = BitChartPosition.Left, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Revenue ($k)" } },
["y2"] = new BitChartScaleOptions { Id = "y2", Type = BitChartScaleType.Linear, Position = BitChartPosition.Right, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Margin %" },
Grid = new BitChartGridOptions { DrawOnChartArea = false } }
}
};
private BitChartData DualAxis() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Type = BitChartType.Bar, Label = "Revenue", YAxisID = "y", Data = new() { 120, 150, 130, 180, 165, 210, 195 }, BackgroundColor = "#36a2eb" },
new BitChartDataset { Type = BitChartType.Line, Label = "Margin", YAxisID = "y2", Data = new() { 18, 22, 20, 26, 24, 30, 28 }, BorderColor = "#ff9f40", Tension = 0.3 }
}
};
```
\n**Rainfall + temperature**:
```razor
@* No top-level Type: each dataset declares its own (Bar/Line). *@
```
```csharp
private readonly BitChartOptions _combo = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom } },
Scales =
{
["y"] = new BitChartScaleOptions
{
Id = "y", Type = BitChartScaleType.Linear, Position = BitChartPosition.Left, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Rainfall (mm)" }
},
["y2"] = new BitChartScaleOptions
{
Id = "y2", Type = BitChartScaleType.Linear, Position = BitChartPosition.Right, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Temp (°C)" },
Grid = new BitChartGridOptions { DrawOnChartArea = false },
Ticks = new BitChartTickOptions { Suffix = "°" }
}
}
};
private BitChartData TempAndRainfall() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Rainfall (mm)", Type = BitChartType.Bar, Data = new() { 60, 48, 80, 35, 55, 20, 15 },
BackgroundColor = "rgba(54,162,235,0.5)", BorderColor = "#36a2eb", YAxisID = "y", Order = 1 },
new BitChartDataset { Label = "Temp (°C)", Type = BitChartType.Line, Data = new() { 7, 9, 12, 16, 20, 24, 27 },
BorderColor = "#ff6384", BackgroundColor = "#ff6384", Tension = 0.4, YAxisID = "y2", Order = 0 }
}
};
```
\n**Two x-axes**:
```razor
```
```csharp
private readonly BitChartOptions _dualX = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom, Labels = new BitChartLegendLabelOptions { UsePointStyle = true } } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Linear, Position = BitChartPosition.Bottom,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Wavelength (nm)" } },
["x2"] = new BitChartScaleOptions { Id = "x2", Type = BitChartScaleType.Linear, Position = BitChartPosition.Top,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Frequency (THz)" },
Grid = new BitChartGridOptions { DrawOnChartArea = false } },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Grace = 0.1 }
}
};
private BitChartData DualX() => new()
{
Datasets =
{
new BitChartDataset
{
Label = "Visible", BackgroundColor = "#36a2eb", XAxisID = "x", PointRadius = 6,
Points = new() { new(450, 20), new(520, 45), new(580, 60), new(640, 38), new(700, 25) }
},
new BitChartDataset
{
Label = "Frequency band", BackgroundColor = "#ff6384", XAxisID = "x2", PointStyle = BitChartPointStyle.Triangle, PointRadius = 6,
Points = new() { new(430, 30), new(500, 55), new(600, 40), new(660, 50) }
}
}
};
```
\n**Fixed min / max**:
```razor
```
```csharp
private readonly BitChartOptions _minMax = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Min = 0, Max = 100 } }
};
private BitChartData Series() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets = { new BitChartDataset { Label = "Value", Data = new() { 35, 52, 48, 70, 60, 78, 66 },
BorderColor = "#36a2eb", BackgroundColor = "#36a2eb", Tension = 0.3 } }
};
```
\n**Explicit step size**:
```razor
```
```csharp
private readonly BitChartOptions _step = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, BeginAtZero = true,
Ticks = new BitChartTickOptions { StepSize = 25 } } }
};
// Series(): Jan..Jul = 35/52/48/70/60/78/66
```
\n**Logarithmic**:
```razor
```
```csharp
private readonly BitChartOptions _log = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Logarithmic } }
};
private BitChartData LogData() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets = { new BitChartDataset { Label = "Growth", Data = new() { 1, 10, 100, 1000, 5000, 20000, 80000 },
BorderColor = "#ff6384", BackgroundColor = "#ff6384", Tension = 0.2 } }
};
```
\n**Reversed Y axis**:
```razor
```
```csharp
private readonly BitChartOptions _reverse = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Reverse = true, Min = 1, Max = 10 } }
};
private BitChartData Rank() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets = { new BitChartDataset { Label = "Rank", Data = new() { 8, 6, 7, 3, 4, 2, 1 },
BorderColor = "#9966ff", BackgroundColor = "#9966ff", Tension = 0.3 } }
};
```
\n**Daily series (auto unit)**:
```razor
```
```csharp
private readonly BitChartOptions _time = new()
{
Animation = new BitChartAnimationOptions { Progressive = true, Duration = 1500 },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales =
{
// A Time scale auto-selects the unit (hour/day/week/month/year) for the range.
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Time },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear }
}
};
// Points carry x as a date (OADate). e.g. 60 daily points:
private BitChartData TimeSeries()
{
var start = new DateTime(2026, 1, 1);
var rnd = new Random(7);
var pts = new List();
double v = 100;
for (int i = 0; i < 60; i++)
{
v += rnd.NextDouble() * 20 - 9;
pts.Add(new BitChartDataPoint(start.AddDays(i).ToOADate(), Math.Round(v, 1)));
}
return new BitChartData
{
Datasets = { new BitChartDataset { Label = "Price", BorderColor = "#36a2eb", Tension = 0.3, Points = pts, PointRadius = 0 } }
};
}
```
\n**Forced month unit + custom format**:
```razor
```
```csharp
private readonly BitChartOptions _month = new()
{
Animation = new BitChartAnimationOptions { Progressive = true, Duration = 1500 },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales =
{
["x"] = new BitChartScaleOptions
{
Id = "x", Type = BitChartScaleType.Time, TimeUnit = BitChartTimeUnit.Week,
TimeFormat = d => d.ToString("d MMM") // custom tick label
},
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear }
}
};
// TimeSeries(): 60 daily points starting 2026-01-01 (see previous card)
```
\n**Interactive legend controls**:
```razor
@* Bind controls to legend options; the chart recomputes on each change. *@
...Top/Bottom/Left/Right...
...Start/Center/End...
Point style
Reverse
```
```csharp
private BitChartPosition _position = BitChartPosition.Top;
private BitChartAlign _align = BitChartAlign.Center;
private bool _usePointStyle;
private bool _reverse;
private BitChartOptions Live() => new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions
{
Position = _position, Align = _align, Reverse = _reverse,
Labels = new BitChartLegendLabelOptions { UsePointStyle = _usePointStyle }
}
}
};
private BitChartData MultiSeries() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Alpha", Data = new() { 65, 59, 80, 81, 56, 55, 72 }, BorderColor = "#36a2eb", BackgroundColor = "#36a2eb", Tension = 0.3 },
new BitChartDataset { Label = "Beta", Data = new() { 28, 48, 40, 60, 86, 92, 78 }, BorderColor = "#ff6384", BackgroundColor = "#ff6384", Tension = 0.3 },
new BitChartDataset { Label = "Gamma", Data = new() { 40, 35, 60, 45, 70, 50, 65 }, BorderColor = "#4bc0c0", BackgroundColor = "#4bc0c0", Tension = 0.3 }
}
};
```
\n**Legend title**:
```razor
```
```csharp
private readonly BitChartOptions _titled = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom, Title = "Product lines" }
}
};
// Revenue(): 3 datasets (Product A/B/C) over Jan..Jul
```
\n**Title & footer callbacks**:
```razor
```
```csharp
private readonly BitChartOptions _footer = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom },
Tooltip = new BitChartTooltipOptions
{
Mode = BitChartInteractionMode.Index,
Callbacks = new BitChartTooltipCallbacks
{
Title = items => items.Count > 0 ? $"Month: {items[0].Label}" : null,
Footer = items => $"Total: {items.Sum(i => i.Value):N0}"
}
}
}
};
// Revenue(): 3 datasets (Product A/B/C) over Jan..Jul
```
\n**Currency labels**:
```razor
```
```csharp
private readonly BitChartOptions _currency = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom },
Tooltip = new BitChartTooltipOptions
{
Mode = BitChartInteractionMode.Index,
Callbacks = new BitChartTooltipCallbacks
{
Label = item => $"{item.DatasetLabel}: {item.Value:C0}"
}
}
}
};
private BitChartData TwoSeries() => new()
{
Labels = { "Q1", "Q2", "Q3", "Q4" },
Datasets =
{
new BitChartDataset { Label = "Revenue", Data = new() { 1200, 1500, 1700, 2100 }, BorderColor = "#36a2eb", BackgroundColor = "#36a2eb", Tension = 0.4 },
new BitChartDataset { Label = "Costs", Data = new() { 800, 950, 1100, 1300 }, BorderColor = "#ff6384", BackgroundColor = "#ff6384", Tension = 0.4 }
}
};
```
\n**After-body note**:
```razor
```
```csharp
private readonly BitChartOptions _afterBody = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom },
Tooltip = new BitChartTooltipOptions
{
Mode = BitChartInteractionMode.Index,
Callbacks = new BitChartTooltipCallbacks
{
AfterBody = items =>
{
if (items.Count < 2) return null;
double diff = items[0].Value - items[1].Value;
return $"Margin: {diff:N0}";
}
}
}
}
};
// TwoSeries(): Revenue & Costs over Q1..Q4
```
\n**Styled box**:
```razor
```
```csharp
private readonly BitChartOptions _styled = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom },
Tooltip = new BitChartTooltipOptions
{
Mode = BitChartInteractionMode.Index,
BackgroundColor = "#ffffff",
TitleColor = "#1f2733",
BodyColor = "#3a4452",
FooterColor = "#1f2733",
BorderColor = "#e0e4ea",
BorderWidth = 1,
TitleAlign = BitChartAlign.Center,
Callbacks = new BitChartTooltipCallbacks { Footer = items => $"{items.Count} series" }
}
}
};
// Revenue(): 3 datasets (Product A/B/C) over Jan..Jul
```
\n**Point-style swatches**:
```razor
```
```csharp
private readonly BitChartOptions _pointStyle = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Position = BitChartPosition.Bottom, Labels = new BitChartLegendLabelOptions { UsePointStyle = true } },
Tooltip = new BitChartTooltipOptions { Mode = BitChartInteractionMode.Index, UsePointStyle = true }
}
};
private BitChartData Markers() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Triangles", Data = new() { 20, 35, 28, 45, 38, 52, 44 },
BorderColor = "#4bc0c0", PointBackgroundColor = "#4bc0c0", PointStyle = BitChartPointStyle.Triangle, PointRadius = 5, Tension = 0.3 },
new BitChartDataset { Label = "Diamonds", Data = new() { 12, 22, 18, 30, 26, 38, 32 },
BorderColor = "#ff9f40", PointBackgroundColor = "#ff9f40", PointStyle = BitChartPointStyle.RectRot, PointRadius = 5, Tension = 0.3 }
}
};
```
\n**Threshold lines**:
```razor
```
```csharp
private BitChartOptions _lines = default!;
protected override void OnInitialized()
{
_lines = new BitChartOptions
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Custom =
{
new BitChartAnnotationPlugin(
new BitChartAnnotation { Orientation = BitChartLineOrientation.Horizontal, Value = 80,
Color = "#2ecc71", Dash = new() { 6, 4 }, Label = "Target" },
new BitChartAnnotation { Kind = BitChartAnnotationKind.Box, YMin = 0, YMax = 30,
Color = "#ff6384", FillColor = "rgba(255,99,132,0.10)", LineWidth = 0, Label = "Low", DrawBehindDatasets = true }
)
}
}
};
}
private BitChartData Series() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets = { new BitChartDataset { Label = "Score", Data = new() { 20, 45, 60, 35, 75, 90, 70 }, BorderColor = "#36a2eb", Tension = 0.4 } }
};
```
\n**Box + vertical marker**:
```razor
```
```csharp
private BitChartOptions _box = default!;
protected override void OnInitialized()
{
_box = new BitChartOptions
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Custom =
{
new BitChartAnnotationPlugin(
new BitChartAnnotation { Kind = BitChartAnnotationKind.Box, XIsIndex = true, XMin = 2, XMax = 4,
Color = "#9966ff", FillColor = "rgba(153,102,255,0.12)", LineWidth = 1, DrawBehindDatasets = true },
new BitChartAnnotation { Orientation = BitChartLineOrientation.Vertical, XIsIndex = true, Value = 3,
Color = "#ff9f40", LineWidth = 2, Label = "Launch" }
)
}
}
};
}
private BitChartData Bars() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets = { new BitChartDataset { Label = "Sales", Data = new() { 30, 42, 55, 70, 64, 48, 52 }, BackgroundColor = "#36a2eb" } }
};
```
\n**Bars**:
```razor
Duration @_duration ms
Easing
ease-out
ease-in-out
spring
linear
Stagger @_stagger ms/el
Randomize data
```
```csharp
private int _duration = 800;
private string _easing = "cubic-bezier(.34,1.56,.64,1)";
private int _stagger = 60;
private BitChartData _data = Build();
private readonly Random _rnd = new();
// Animation maps to CSS transitions in the browser.
private BitChartOptions Opts() => new()
{
Animation = new BitChartAnimationOptions { Duration = _duration, Easing = _easing, DelayBetween = _stagger },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private static BitChartData Build() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Value", Data = new() { 40, 65, 50, 80, 60, 72, 55 },
BackgroundColor = "#36a2eb", BorderRadius = 6 }
}
};
private void Randomize()
{
var d = _data.Datasets[0].Data;
for (int i = 0; i < d.Count; i++) d[i] = _rnd.Next(20, 100);
_data = new BitChartData { Labels = _data.Labels, Datasets = { _data.Datasets[0] } };
}
```
\n**Line draw-on**:
```razor
Duration @_duration ms
Easing
ease-out
ease-in-out
spring
linear
Stagger @_stagger ms/el
Randomize data
```
```csharp
private int _duration = 800;
private string _easing = "cubic-bezier(.34,1.56,.64,1)";
private int _stagger = 60;
private BitChartData _data = Build();
private readonly Random _rnd = new();
private BitChartOptions Opts() => new()
{
Animation = new BitChartAnimationOptions { Duration = _duration, Easing = _easing, DelayBetween = _stagger },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private static BitChartData Build() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Trend", Data = new() { 40, 65, 50, 80, 60, 72, 55 },
BorderColor = "#9966ff", Tension = 0.4, PointRadius = 4, PointBackgroundColor = "#9966ff" }
}
};
private void Randomize()
{
var d = _data.Datasets[0].Data;
for (int i = 0; i < d.Count; i++) d[i] = _rnd.Next(20, 100);
_data = new BitChartData { Labels = _data.Labels, Datasets = { _data.Datasets[0] } };
}
```
\n**Color by sign**:
```razor
```
```csharp
private readonly BitChartOptions _noLegend = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private BitChartData BySign() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset
{
Label = "Net change",
Data = new() { 12, -8, 22, -4, 18, -15, 9 },
BorderRadius = 4,
// Scriptable: receives a context per element
BackgroundColorFn = ctx => (ctx.Value ?? 0) < 0 ? "#ff6384" : "#4bc0c0"
}
}
};
```
\n**Color by threshold**:
```razor
```
```csharp
private readonly BitChartOptions _noLegend = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private BitChartData ByThreshold() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset
{
Label = "Score",
Data = new() { 60, 72, 80, 68, 91, 55, 84 },
BorderColor = "#36a2eb",
Tension = 0.3,
PointRadius = 5,
PointBackgroundColorFn = ctx => (ctx.Value ?? 0) >= 75 ? "#ff9f40" : "#36a2eb",
PointRadiusFn = ctx => (ctx.Value ?? 0) >= 75 ? 7 : 4
}
}
};
```
\n**Decimated line (zoom + pan)**:
```razor
```
```csharp
private const int _count = 5000;
private const int _samples = 250;
private BitChartData _data = default!;
private readonly BitChartOptions _options = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
// LTTB downsampling keeps thousands of points smooth.
Decimation = new BitChartDecimationOptions { Enabled = true, Samples = _samples, Threshold = 400 },
Tooltip = new BitChartTooltipOptions { Enabled = false }
},
Zoom = new BitChartZoomOptions { Enabled = true, Mode = BitChartZoomMode.X },
Scales = { ["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Time } }
};
protected override void OnInitialized() => _data = BuildLargeSeries(_count);
```
\n**Drag-to-zoom box**:
```razor
```
```csharp
// DragZoom + Wheel = false: drag a rectangle to zoom into it.
private readonly BitChartOptions _drag = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Zoom = new BitChartZoomOptions { Enabled = true, Mode = BitChartZoomMode.XY, DragZoom = true, Wheel = false }
};
// Scatter(): 400-point random cloud (see "Zoom both axes" card)
```
\n**Category-axis zoom**:
```razor
```
```csharp
private readonly BitChartOptions _catZoom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Zoom = new BitChartZoomOptions { Enabled = true, Mode = BitChartZoomMode.X }
};
private BitChartData ManyBars()
{
var rnd = new Random(11);
var labels = Enumerable.Range(1, 40).Select(i => $"D{i}").ToList();
var data = Enumerable.Range(0, 40).Select(_ => (double?)Math.Round(rnd.NextDouble() * 80 + 20, 0)).ToList();
return new BitChartData
{
Labels = labels,
Datasets = { new BitChartDataset { Label = "Daily", Data = data, BackgroundColor = "#4bc0c0" } }
};
}
```