# Chart
**Also known as:** Graph, Plot
## Description
BitChart renders native SVG computed in C# - no canvas or JavaScript engine - so it works in prerendering and static SSR. A Chart.js-like API (BitChartType + BitChartData + BitChartOptions, or one BitChartConfig) draws line, bar, area, pie, doughnut, polar area, radar, scatter, bubble, mixed and sparkline charts, styled by the bit theme and public --bit-Chart-* CSS variables, with keyboard and screen-reader support and SVG/PNG/CSV export.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Classes | `BitChartClassStyles?` | null | Custom CSS classes for the parts of the chart: root, title, subtitle, legend, legend items, plot, tooltip, empty state and loading state. |
| Config | `BitChartConfig?` | null | Full configuration (type + data + options). Takes precedence over Type/Data/Options when set. |
| Data | `BitChartData?` | null | The chart data: labels and datasets. |
| Description | `string?` | null | A visually hidden summary of what the chart shows - its trend or takeaway - that the plot is described by: the long description a complex image needs beside its name and its data table. |
| EmptyTemplate | `RenderFragment?` | null | Custom content shown in place of the plot when there is nothing to draw. Takes precedence over EmptyText. |
| EmptyText | `string` | null | Message shown in place of the plot when the configuration produces nothing to draw. Defaults to BitStrings.NoItemsFound ("No items found"). |
| GenerateTable | `bool` | true | Renders a visually hidden data table right after the chart, which a screen reader can browse cell by cell. |
| Height | `string?` | null | Optional CSS height of the chart container. When null the height follows the aspect ratio. |
| Loading | `bool` | false | Shows a loading veil with a spinner over the plot, marks the chart aria-busy and holds back the empty state, so a chart still waiting for its data does not claim it has none. |
| LoadingLabel | `string?` | "Loading" | The text shown under the spinner, and announced, while Loading is set. |
| LoadingTemplate | `RenderFragment?` | null | Custom content shown in place of the default spinner while Loading is set. |
| MaxTableColumns | `int` | 100 | Upper bound on the columns the screen-reader table renders. A value series is one row with a cell per category, so a long one is wide rather than tall and the row cap alone would not contain it. Ignored for scatter and bubble data, whose table is three fixed columns. |
| MaxTableRows | `int` | 500 | Upper bound on the rows the screen-reader table renders, so a long series does not put tens of thousands of hidden nodes in the DOM. Past the limit the caption says how many rows were left out. |
| NavigationHint | `string?` | "Interactive chart. Use the left and right arrow keys..." | A visually hidden sentence telling a screen-reader user how to walk the data, pointed at by aria-describedby. Only rendered while there is data to navigate; set it to null to leave it out. |
| OnElementClick | `EventCallback<(int DatasetIndex, int DataIndex)>` | | Callback raised when a data element (point, bar, arc, ...) is clicked, by pointer or with Enter/Space while it is focused. |
| OnElementHover | `EventCallback<BitChartTooltipContext?>` | | Callback raised when the active (hovered or keyboard-focused) element set changes. The context is null once nothing is active. |
| OnLegendItemClick | `EventCallback<BitChartLegendItemModel>` | | Callback raised when a legend item is clicked, before the default visibility toggle runs. |
| OnZoomChange | `EventCallback` | | Callback raised after zoom or pan changes the visible axis ranges. |
| Options | `BitChartOptions?` | null | The chart options: scales, plugins (title, legend, tooltip, data labels), interaction, animation, culture and zoom. |
| Strings | `BitChartStrings?` | null | The strings written for assistive technologies and into the CSV export: the default accessible name, the legend's name, the keyboard announcements, the table headers and captions. English by default; override them to localize. |
| Styles | `BitChartClassStyles?` | null | Custom CSS styles for the parts of the chart: root, title, subtitle, legend, legend items, plot, tooltip, empty state and loading state. |
| TooltipTemplate | `RenderFragment<BitChartTooltipContext>?` | null | Optional custom tooltip template. When set it replaces the default tooltip body. |
| Type | `BitChartType` | BitChartType.Line | The chart type: Line, Bar, Radar, Pie, Doughnut, PolarArea, Bubble or Scatter. |
| Width | `string` | 100% | CSS width of the chart container. |
| ZoomHint | `string?` | "Press plus or minus to zoom, and 0 to reset the zoom." | Appended to NavigationHint while zoom is enabled, naming the zoom keys. Set it to null to leave it out. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| Disabled | `bool` | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Refresh | `void Refresh()` | | Rebuilds and redraws the chart from its current data and options. Blazor only re-renders on a parameter change it can see, so mutating the same BitChartData in place - appending to a live series, editing a value - needs this call. The counterpart of Chart.js's chart.update(). |
| IsDatasetVisible | `bool IsDatasetVisible(int datasetIndex)` | | Whether a dataset is currently drawn, i.e. hidden neither through the legend nor by BitChartDataset.Hidden. |
| SetDatasetVisible | `void SetDatasetVisible(int datasetIndex, bool visible)` | | Shows or hides a dataset, exactly as clicking its legend entry would; the axes re-scale around what is left. |
| ToggleDataset | `void ToggleDataset(int datasetIndex)` | | Flips a dataset between shown and hidden. |
| IsDataIndexVisible | `bool IsDataIndexVisible(int dataIndex)` | | Whether a data index - a pie, doughnut or polar-area slice - is currently drawn. |
| SetDataIndexVisible | `void SetDataIndexVisible(int dataIndex, bool visible)` | | Shows or hides one data index across the chart, the slice-level counterpart of SetDatasetVisible. |
| ToggleDataIndex | `void ToggleDataIndex(int dataIndex)` | | Flips one data index between shown and hidden. |
| ResetVisibility | `void ResetVisibility()` | | Brings back every dataset and data index hidden through the legend or the API. |
| ResetZoom | `void ResetZoom()` | | Clears every zoom/pan override and returns the chart to the full data range. |
| ZoomTo | `void ZoomTo(string axisId, double? min, double? max)` | | Zooms an axis to an explicit value range, honoring the configured zoom limits. Pass null bounds to clear that axis's override. |
| GetAxisRange | `(double Min, double Max)? GetAxisRange(string axisId)` | | The currently visible range of an axis: its zoomed range when zoomed, otherwise the full data range. |
| ExportSvgAsync | `Task<bool> ExportSvgAsync(string? fileName = null, string? backgroundColor = null)` | | Downloads the chart as a standalone .svg file, with the theme tokens it references resolved into the file. |
| ExportPngAsync | `Task<bool> ExportPngAsync(string? fileName = null, double scale = 2, string? backgroundColor = SurfaceBackground)` | | Downloads the chart as a .png image rasterized from the live SVG at the given pixel ratio, on the surface the chart sits on (so a dark theme exports dark); pass a color of your own, or null for a transparent image. |
| ExportCsvAsync | `Task<bool> ExportCsvAsync(string? fileName = null)` | | Downloads the chart's data as a .csv file, formatted with the chart's culture. |
| ToCsv | `string ToCsv()` | | Returns the chart's data as CSV text: one row per series for value datasets, one row per point for scatter and bubble datasets. |
| ToSvgStringAsync | `Task<string?> ToSvgStringAsync(string? backgroundColor = null)` | | Returns the chart as standalone SVG markup instead of downloading it, with the theme tokens it references resolved into the markup. Null when the chart has not been rendered in a browser yet. |
| ToBase64ImageAsync | `Task<string?> ToBase64ImageAsync(string mimeType = "image/png", double scale = 2, string? backgroundColor = SurfaceBackground)` | | Returns the rasterized chart as a data: URL - the same picture ExportPngAsync downloads - ready for an img src or a PDF. Mirrors Chart.js's toBase64Image. |
| SurfaceBackground | `const string` | "var(--bit-Chart-surface-color, var(--bit-clr-bg-pri))" | The default background of ExportPngAsync and ToBase64ImageAsync: the surface the chart sits on, resolved in the browser. |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## Sub Classes
### BitChartClassStyles Properties
Defines per-part CSS class/style values for BitChart.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom class or style applied to the root element. |
| Title | `string?` | null | Custom class or style applied to the title. |
| Subtitle | `string?` | null | Custom class or style applied to the subtitle. |
| Legend | `string?` | null | Custom class or style applied to the legend container. |
| LegendItem | `string?` | null | Custom class or style applied to each legend item. |
| Plot | `string?` | null | Custom class or style applied to the plot container that holds the SVG, the tooltip and the empty state. |
| Tooltip | `string?` | null | Custom class or style applied to the tooltip box, the default one and a custom template's alike. |
| Empty | `string?` | null | Custom class or style applied to the empty state shown when there is nothing to draw. |
| Loading | `string?` | null | Custom class or style applied to the loading state shown over the plot while the chart is loading. |
### BitChartStrings Properties
The strings BitChart writes for assistive technologies and into its CSV export. All default to English; the ...Format ones are composite format strings filled in the chart's culture.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| DefaultAriaLabelFormat | `string` | "{0} chart with {1} data series." | Accessible name of a chart with neither an AriaLabel nor a displayed title. {0} is the chart type, {1} the number of series. |
| RoleDescription | `string` | "chart" | What a screen reader calls the plot in place of its role (aria-roledescription). |
| TypeNames | `Dictionary<BitChartType, string>` | "Line", "Bar", ... "Polar area" | The name of each chart type, filled into {0} of DefaultAriaLabelFormat. |
| NotesFormat | `string` | "Marked on the chart: {0}." | The hidden sentence the plot is described by that names what the plugins drew - annotations, labeled trend lines, a center text. {0} is the list of them. |
| LegendAriaLabel | `string` | "Chart legend" | Accessible name of a legend that has no title of its own. |
| PositionFormat | `string` | "{0} of {1}" | Announced after the keyboard-focused value: its position within its series. |
| SeriesPositionFormat | `string` | "series {0} of {1}" | Announced when the chart has more than one series: which one the focused value belongs to. |
| DatasetLabelFormat | `string` | "Dataset {0}" | Name of a dataset without a Label, in the legend, the table and the CSV alike. {0} is the 1-based dataset number. |
| Series | `string` | "Series" | Header of the series column of the table and the CSV. |
| X / Y | `string` | "X" / "Y" | Headers of the point columns of scatter and bubble data, used when the axis shows no title of its own. |
| Radius | `string` | "R" | Header of the radius column of bubble data. |
| RowsTruncatedFormat / ColumnsTruncatedFormat | `string` | "Showing the first {0} of {1} rows." / "... columns." | Appended to the table's caption when MaxTableRows / MaxTableColumns cut it short. |
### 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. Colors, radii and styles marked *Fn are scriptable: they receive a BitChartScriptableContext per element and take precedence over the constant beside them.
| 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). A null is a gap, not a zero. |
| Points | `List<BitChartDataPoint>?` | null | Point data (x, y[, r]) for scatter, bubble and time-based line charts. When set, takes precedence over Data. |
| RangeData | `List<(double Low, double High)?>?` | null | Floating-bar ranges per index. When set, bars span low to high instead of growing from the base. |
| 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 the area fill of a filled line. |
| BackgroundColors | `List<string>?` | null | One fill color per data index, cycled when shorter than the data. |
| BorderColor | `string?` | null | The line/border color. Bars and arcs fall back to their own fill color rather than an unrelated palette entry. |
| BorderWidth | `double?` | null | Border/line thickness. When null a per-type default applies: 3 for lines and radar, 2 for arcs, and 0 for bars unless a border color was given. |
| Fill | `BitChartFillMode` | BitChartFillMode.None | Area fill mode for line/radar datasets (None, Origin, Start, End, Stack, Dataset, Value). |
| FillGradient | `BitChartGradientBase?` | null | A linear or radial gradient used for the area fill, taking precedence over FillColor and BackgroundColor. |
| BackgroundPattern | `BitChartFillPattern?` | null | A repeating hatch/grid/dot texture used instead of a solid fill; keeps series distinguishable in print and greyscale. |
| Tension | `double` | 0 | Bezier curve tension for line datasets (0 = straight lines). |
| Stepped | `BitChartSteppedLine` | BitChartSteppedLine.False | Draws the line as steps (Before, After or Middle) instead of interpolating. |
| SpanGaps | `bool` | false | Bridges null values instead of breaking the line at them. |
| Segment | `BitChartLineSegmentStyle?` | null | Per-segment color, width and dash callbacks, evaluated from the two endpoints of each segment. |
| PointRadius | `double` | 3 | Marker radius. Zero hides the marker but keeps the point hoverable. |
| PointStyle | `BitChartPointStyle` | BitChartPointStyle.Circle | Marker shape. BitChartPointStyle.None removes the markers - and their hit targets - entirely. |
| Stack | `string?` | null | Stack group id. Datasets sharing an id accumulate together; each group gets its own column. |
| Grouped | `bool` | true | When false the bar dataset leaves the side-by-side layout and keeps the whole category band, so it can sit behind the others. |
| SkipNull | `bool` | false | Lets the remaining bars of a category widen over the datasets that have no value there, instead of leaving a hole. |
| MinBarLength | `double?` | null | Minimum bar length in pixels, so near-zero values stay visible. |
| Base | `double?` | null | The value bars grow from. Defaults to zero clamped into the axis range. |
| BorderRadius | `double` | 0 | Corner radius. On a bar only the corners away from the skipped (baseline) edge are rounded, and BorderRadiusCorners overrides each corner; on a pie, doughnut or polar-area arc it rounds the arc's own corners, clamped to half the ring's thickness. |
| Offset / SpacingArc / HoverOffset | `double` | 0 / 0 / 6 | Arc geometry: how far every slice sits from the center, the gap left between neighbouring slices, and the extra distance the hovered slice pops out. |
| Weight | `double` | 1 | Relative thickness of this dataset's ring in a multi-dataset pie or doughnut. The available radius is shared out in proportion to the weights. |
| ErrorData | `List<BitChartErrorBar?>?` | null | Per-index uncertainty, drawn as a capped whisker through the value and named in the tooltip. A BitChartErrorBar comes from one number (symmetric) or two (asymmetric); a null entry leaves that value bare. Cartesian charts only. |
| ErrorBarColor / ErrorBarWidth / ErrorBarCapWidth | `string? / double / double` | null / 1.5 / 8 | Error-bar styling. A null color follows the primary foreground token; a zero cap width draws a bare whisker. |
| HoverBackgroundColor / HoverBorderColor / HoverBorderWidth | `string? / string? / double?` | null | Styling used while a bar or arc is hovered or keyboard-focused. |
| XAxisID / YAxisID / RAxisID | `string` | x / y / r | The scales this dataset is bound to. Naming a scale that does not exist yet creates a linear one. |
| Order | `int` | 0 | Draw order across datasets; lower draws first. Bars are always drawn before lines and points. |
| Hidden | `bool` | false | Hides the dataset without removing it, and marks its legend entry as toggled off. |
### BitChartOptions Properties
Top-level chart options, mirroring Chart.js options. The same instance can safely be shared between charts: the renderer completes the missing scales locally instead of writing them back.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Responsive | `bool` | true | Observes the container and renders at real device pixels, which keeps font sizes constant at any width. |
| MaintainAspectRatio / AspectRatio | `bool / double?` | true / null | Whether the height follows the width, and the ratio to use. Defaults to 2 for cartesian charts and 1 for circular and radar ones. |
| IndexAxis | `BitChartIndexAxis` | BitChartIndexAxis.X | The axis the data index runs along: X for vertical bars, Y for horizontal ones. |
| Sparkline | `bool` | false | Draws the chart as a sparkline: axes, grid, tick labels, legend, title and subtitle are all dropped so the series fills the box. A presentation switch only - tooltips, keyboard navigation and the screen-reader table still describe the full series. |
| Scales | `Dictionary<string, BitChartScaleOptions>` | new() | Named scales keyed by id (x, y, r, y2, ...): type, min/max, grid, ticks, title, stacking, time unit and radial options. |
| Interaction | `BitChartInteractionOptions` | new() | Mode (Nearest, Index, Dataset, ...) and Intersect. With Intersect false - the default - hit bands make the whole plot hoverable, marked by a crosshair and an axis chip (Crosshair / CrosshairLabel / CrosshairColor). The tooltip inherits Mode and Intersect unless it overrides them. |
| Plugins | `BitChartPluginOptions` | new() | Title, Subtitle, Legend, Tooltip, DataLabels and Decimation options, plus Custom for your own IBitChartPlugin drawing plugins. |
| Animation | `BitChartAnimationOptions` | new() | Duration, easing, per-element stagger (DelayBetween) and the progressive draw-on for line charts. |
| Elements | `BitChartElementOptions` | new() | Per-type defaults used whenever a dataset leaves the matching property unset. |
| Layout | `BitChartLayoutOptions` | new() | Padding around the whole chart. |
| Zoom | `BitChartZoomOptions` | new() | Wheel zoom, drag pan, drag-to-zoom box, axis mode, speed, and the limits that keep the view inside the data. |
| Culture | `CultureInfo?` | null | Culture used for every number and date the chart prints - ticks, tooltips, data labels and the CSV export. Null means the invariant culture. |
| CutoutPercentage / CircumferenceDegrees / RotationDegrees | `double` | 50 / 360 / -90 | Doughnut hole size, sweep and starting angle. A 180 degree sweep turns a doughnut into a gauge. |
### BitChartAnnotation Properties
One line, box, ellipse, polygon, point or label drawn in data coordinates by BitChartAnnotationPlugin, which is registered through Options.Plugins.Custom. Cartesian charts only.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Kind | `BitChartAnnotationKind` | Line | The shape: Line, Box, Point, Label, Ellipse or Polygon. |
| Orientation / Value / AxisId | `BitChartLineOrientation / double / string` | Horizontal / 0 / "y" | Where a line is drawn: a y value for a horizontal line, an x value (or category index with XIsIndex) for a vertical one. |
| XMin / XMax / YMin / YMax / XIsIndex | `double? / bool` | null / false | The bounds of a box or an ellipse in data coordinates; a null bound runs to the edge of the plot. XIsIndex reads the X values as category indices. |
| Sides / Radius / Rotation | `int / double? / double` | 3 / null / 0 | The shape of a polygon, and the pixel radius of a polygon or a point. |
| Color / FillColor / LineWidth / Dash | `string / string? / double / List<double>?` | --bit-Chart-annotation-color / null / 2 / null | Styling. A null fill is the color made translucent. |
| Label / LabelColor / LabelBackground / LabelFont | `string? / string / string? / BitChartFont` | null / --bit-Chart-annotation-label-color / null / 11px bold | An optional pill beside the shape. A null background follows Color. |
| Description | `string?` | null | What a screen reader is told about the annotation, in place of its label and value. The drawing is hidden from assistive technologies, so an annotation with neither a Label nor a Description is treated as decoration. |
| DrawBehindDatasets | `bool` | false | Draws the annotation under the datasets rather than over them. |
### BitChartTrendline Properties
One fitted line drawn over a dataset by BitChartTrendlinePlugin, which is registered through Options.Plugins.Custom. Cartesian charts only.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| DatasetIndex | `int` | 0 | Index of the dataset the line is fitted to. A dataset hidden through the legend takes its trend line with it. |
| Kind | `BitChartTrendlineKind` | BitChartTrendlineKind.Linear | Linear for a least-squares regression, MovingAverage for a trailing average over Period points, or Average for a flat line at the series mean. |
| Period | `int` | 5 | Window of the trailing moving average. Ignored by the other kinds. |
| Extend | `bool` | false | Projects a straight fit out to both edges of the plot instead of stopping at the first and last data point. Ignored by MovingAverage, which has no meaning outside the data. |
| Color / LineWidth / Dash | `string? / double / List<double>?` | null / 2 / [6, 4] | Line styling. A null color follows the dataset's own border color; the dash is what keeps the fit from reading as another measured series - set it to null for a solid line. |
| Label / LabelColor / LabelBackground / LabelFont | `string? / string / string? / BitChartFont` | null / #fff / null / 11px bold | An optional pill drawn at the end of the line, pinned inside the plot so it stays readable at the edge. A labeled line is also named to screen readers. |
| DrawBehindDatasets | `bool` | false | Draws the line under the datasets rather than over them. |
## CSS Variables
Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves.
| Name | Default Value | Description |
| :--- | :------------ | :---------- |
| `--bit-Chart-font-family` | --bit-tpg-font-family | Typeface of every text the chart draws: title, legend, ticks, labels and tooltip. |
| `--bit-Chart-series-color-1 ... --bit-Chart-series-color-10` | The Chart.js palette (#36a2eb, #ff6384, #4bc0c0, ...) | The default palette, one color per series - or per slice of a pie, doughnut or polar area. Only used where the dataset names no color; its translucent area and hover shades are derived from it. |
| `--bit-Chart-title-color` | --bit-clr-fg-pri | Color of the title. |
| `--bit-Chart-subtitle-color` | --bit-clr-fg-sec | Color of the subtitle. |
| `--bit-Chart-legend-color` | --bit-clr-fg-sec | Color of the legend labels. |
| `--bit-Chart-tick-color` | --bit-clr-fg-sec | Color of the axis tick labels and the radar / polar point labels. |
| `--bit-Chart-axis-title-color` | --bit-clr-fg-sec | Color of the axis titles. |
| `--bit-Chart-axis-color` | --bit-clr-brd-pri | Color of the axis border lines. |
| `--bit-Chart-grid-color` | --bit-clr-brd-sec | Color of the grid lines, the tick marks and the radar angle lines. Minor grid lines draw it at 40%. |
| `--bit-Chart-data-label-color` | --bit-clr-fg-pri | Color of the data labels. |
| `--bit-Chart-crosshair-color` | --bit-clr-fg-sec | Color of the crosshair through the hovered index. |
| `--bit-Chart-annotation-color` | --bit-clr-fg-sec | Default color of an annotation's line or outline, its translucent fill and its label pill. BitChartAnnotation.Color overrides it. |
| `--bit-Chart-annotation-label-color` | --bit-clr-bg-pri | Default text color of an annotation's label. BitChartAnnotation.LabelColor overrides it. |
| `--bit-Chart-center-text-color` | --bit-clr-fg-pri | Color of the text BitChartCenterTextPlugin draws in a doughnut's cutout. |
| `--bit-Chart-surface-color` | --bit-clr-bg-pri | The surface the chart sits on: the border that separates pie and doughnut slices, and the backdrop behind radial tick labels. Set it to the card color when the chart sits on a card. |
| `--bit-Chart-tooltip-background` | --bit-clr-tooltip-bg | Fill of the tooltip and its caret, and of the crosshair's axis chip. |
| `--bit-Chart-tooltip-color` | --bit-clr-tooltip-fg | Text color of the tooltip and of the crosshair's axis chip. |
| `--bit-Chart-tooltip-radius` | --bit-shp-radius-popup | Corner radius of the tooltip. Tooltip.CornerRadius in the options overrides it. |
| `--bit-Chart-tooltip-shadow` | --bit-shd-tooltip | Elevation of the tooltip. |
| `--bit-Chart-focus-color` | --bit-clr-pri-focus | Focus ring of the plot and the legend items, and the dashed outline of the element the keyboard is on. While it is unset, the focus ring is the library's own --bit-shd-focus-ring, so replacing that token re-shapes it too; the outline is a stroke, drawn in the primary focus color. |
| `--bit-Chart-zoom-box-background` | --bit-clr-pri at 20% | Fill of the drag-to-zoom selection box. |
| `--bit-Chart-zoom-box-border-color` | --bit-clr-pri | Border of the drag-to-zoom selection box. |
| `--bit-Chart-inactive-opacity` | 0.2 | Opacity of the series faded behind a legend item that is hovered or focused (Legend.HighlightOnHover). |
| `--bit-Chart-empty-color` | --bit-clr-fg-sec | Color of the empty-state message. |
| `--bit-Chart-loading-background` | --bit-clr-bg-pri at 70% | The veil laid over the plot while Loading is set; translucent, so the chart behind it shows through. |
| `--bit-Chart-loading-color` | --bit-clr-fg-sec | Color of the loading label. |
| `--bit-Chart-loading-spinner-color` | --bit-clr-pri | Color of the turning arc of the loading spinner. |
## Examples
## Line
Line charts: smooth or straight lines, area fills, steps, dashed borders, logarithmic axes, per-segment styling, monotone smoothing and sparklines.
\n**Smooth line with area fill**:
```razor
```
```csharp
private readonly BitChartOptions _legendBottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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**Sparkline**:
```razor
@foreach (var tile in _tiles)
{
}
```
```csharp
// Sparkline hides the axes, grid, legend and title; turning off MaintainAspectRatio lets the
// chart take the tile's own height instead of one derived from its width.
private readonly BitChartOptions _sparkline = new()
{
Sparkline = true,
MaintainAspectRatio = false,
Layout = new BitChartLayoutOptions { Padding = 2 }
};
private sealed record SparklineTile(string Caption, string Value, BitChartType Type, BitChartData Data);
private readonly List _tiles =
[
new("Sessions", "12,480", BitChartType.Line, Spark("#36a2eb", true, 30, 34, 31, 40, 44, 41, 52, 58, 55, 64)),
new("Signups", "934", BitChartType.Bar, Spark("#4bc0c0", false, 12, 18, 15, 22, 19, 26, 24, 31, 28, 35)),
new("Errors", "17", BitChartType.Line, Spark("#ff6384", true, 22, 19, 24, 16, 14, 18, 11, 9, 12, 7))
];
private static BitChartData Spark(string color, bool line, params double?[] values) => new()
{
// A category axis spans the labels, so a sparkline still needs one per value - blank, since the
// tile shows no axis - or every point lands on the same x.
Labels = [.. values.Select(_ => "")],
Datasets =
{
new BitChartDataset
{
Data = [.. values],
BorderColor = color,
BackgroundColor = color,
PointRadius = 0,
BorderWidth = 2,
Tension = 0.35,
Fill = line ? BitChartFillMode.Origin : BitChartFillMode.None,
FillColor = line ? BitChartColorUtil.WithAlpha(color, 0.18) : null,
BorderRadius = 2
}
}
};
```
## Bar
Grouped, stacked, horizontal, floating and 100% stacked bars, rounded corners, pattern fills, stacked groups, error bars and waterfalls.
\n**Grouped**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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**Minimum length and a custom base**:
```razor
```
```csharp
private readonly BitChartOptions _target = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Title = new BitChartScaleTitleOptions { Display = true, Text = "Units" } } }
};
private BitChartData AgainstTarget() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset
{
Label = "Units vs target",
Data = new() { 118, 96, 100.2, 131, 88, 104, 112 },
Base = 100, // bars grow from the target instead of zero
MinBarLength = 6, // a value that is almost on target still shows
BorderRadius = 3,
BackgroundColorFn = ctx => ctx.Value >= 100 ? "#2ecc71" : "#ff6384"
}
}
};
```
\n**Overlaid series and skipped gaps**:
```razor
```
```csharp
private BitChartData Overlay() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
// Grouped = false steps out of the side-by-side layout and keeps the whole band.
new BitChartDataset
{
Label = "Budget", Grouped = false,
Data = new() { 20, 22, 24, 26, 28, 30, 32 },
BackgroundColor = "rgba(120,130,145,0.25)"
},
new BitChartDataset
{
Label = "Team A", SkipNull = true,
Data = new() { 12, 19, 14, 22, 18, 25, 20 },
BackgroundColor = "#36a2eb", BorderRadius = 3
},
// The nulls leave no gap: Team A widens over those categories.
new BitChartDataset
{
Label = "Team B", SkipNull = true,
Data = new() { 8, null, 17, null, 14, 12, 19 },
BackgroundColor = "#ff9f40", BorderRadius = 3
}
}
};
```
\n**Error bars**:
```razor
```
```csharp
private BitChartData Measured() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset
{
Label = "Response time (ms)",
Data = new() { 120, 138, 131, 156, 149, 162, 158 },
BackgroundColor = "rgba(54,162,235,0.55)",
BorderColor = "#36a2eb",
BorderRadius = 4,
// A number is a symmetric interval; BitChartErrorBar(minus, plus) is asymmetric;
// null leaves that value without a whisker.
ErrorData = [12, 9, 15, new BitChartErrorBar(6, 24), 11, null, 8],
ErrorBarColor = "#1f2733"
}
}
};
```
\n**Waterfall**:
```razor
```
```csharp
// Each step is a signed change, except the two totals which are drawn from the axis.
private static readonly (string Label, double Step, bool IsTotal)[] Steps =
[
("Opening", 120, true),
("New", 46, false),
("Upsell", 18, false),
("Churn", -32, false),
("Discounts", -11, false),
("Expansion", 24, false),
("Closing", 0, true)
];
private readonly BitChartOptions _waterfall = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Tooltip = new BitChartTooltipOptions
{
Callbacks = new BitChartTooltipCallbacks
{
Label = item =>
{
var (label, step, isTotal) = Steps[item.DataIndex];
return isTotal ? $"{label}: {WaterfallTotalAt(item.DataIndex):N0}"
: $"{label}: {step:+#,##0;-#,##0;0}";
}
}
}
}
};
// The running total once the given step has been applied.
private static double WaterfallTotalAt(int index)
{
double total = 0;
for (int i = 0; i <= index; i++) total += Steps[i].Step;
return total;
}
private BitChartData Waterfall()
{
// RangeData floats each bar between the running total before and after its step.
var ranges = new List<(double Low, double High)?>();
double running = 0;
foreach (var (_, step, isTotal) in Steps)
{
if (isTotal) { running += step; ranges.Add((0, running)); continue; }
double next = running + step;
ranges.Add((Math.Min(running, next), Math.Max(running, next)));
running = next;
}
return new BitChartData
{
Labels = Steps.Select(s => s.Label).ToList(),
Datasets =
{
new BitChartDataset
{
Label = "MRR",
RangeData = ranges,
BorderRadius = 3,
BackgroundColorFn = ctx =>
{
var (_, step, isTotal) = Steps[ctx.DataIndex];
return isTotal ? "#6b7785" : step >= 0 ? "#2ecc71" : "#ff6384";
}
}
}
};
}
```
## Area
Gradient and radial fills, stacked areas, ranges filled between datasets and fill boundaries.
\n**Stacked area**:
```razor
```
```csharp
private readonly BitChartOptions _stacked = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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 }
}
};
```
## Pie & Doughnut
Pie and doughnut charts, gauges, multiple rings, a KPI in the center, spacing, offsets and rounded arcs.
\n**Pie**:
```razor
```
```csharp
private readonly BitChartOptions _right = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.End } }
};
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 { Placement = BitPlacement.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 { Placement = BitPlacement.End } }
};
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 { Placement = BitPlacement.End },
Custom = { new BitChartCenterTextPlugin("1,340", "sessions") }
}
};
// Traffic(): Direct/Organic/Referral/Social/Email = 300/500/180/240/120
```
\n**Spacing, offset and hover**:
```razor
```
```csharp
private readonly BitChartOptions _exploded = new()
{
CutoutPercentage = 45,
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.End } }
};
private BitChartData Exploded() => new()
{
Labels = { "Direct", "Organic", "Referral", "Social", "Email" },
Datasets =
{
new BitChartDataset
{
Label = "Sessions",
Data = new() { 300, 500, 180, 240, 120 },
SpacingArc = 6, // gap between neighbouring slices
Offset = 4, // every slice sits slightly off center
HoverOffset = 14, // the hovered one pops out further
HoverBackgroundColor = "#1f2733"
}
}
};
```
\n**Rounded arcs and ring weights**:
```razor
```
```csharp
private readonly BitChartOptions _rounded = new()
{
CutoutPercentage = 35,
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.End } }
};
private BitChartData Weighted() => new()
{
Labels = { "Mobile", "Desktop", "Tablet" },
Datasets =
{
// Weight 2 vs 1: the outer ring gets two thirds of the available radius.
new BitChartDataset { Label = "2026", Data = new() { 62, 28, 10 }, BorderRadius = 8, SpacingArc = 4, Weight = 2 },
new BitChartDataset { Label = "2025", Data = new() { 55, 35, 10 }, BorderRadius = 8, SpacingArc = 4, Weight = 1 }
}
};
```
## Polar area
Polar area charts and their point labels.
\n**Polar area**:
```razor
```
```csharp
private readonly BitChartOptions _right = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.End } }
};
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 } }
}
};
```
## Radar
Radar charts, filled or outlined, on a circular grid, with skipped points.
\n**Two players**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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 }
}
};
```
## Scatter & Bubble
Scatter and bubble charts.
\n**Scatter**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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)
}
}
}
};
```
## Mixed
Bars and lines in one chart, on one axis or two.
\n**Bar + line**:
```razor
```
```csharp
private readonly BitChartOptions _bottom = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.Bottom } },
Scales =
{
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Placement = BitPlacement.Left, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Revenue ($k)" } },
["y2"] = new BitChartScaleOptions { Id = "y2", Type = BitChartScaleType.Linear, Placement = BitPlacement.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 }
}
};
```
## Multi-axis
Several y axes, and two x axes, in one chart.
\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 { Placement = BitPlacement.Bottom } },
Scales =
{
["y"] = new BitChartScaleOptions
{
Id = "y", Type = BitChartScaleType.Linear, Placement = BitPlacement.Left, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Rainfall (mm)" }
},
["y2"] = new BitChartScaleOptions
{
Id = "y2", Type = BitChartScaleType.Linear, Placement = BitPlacement.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 { Placement = BitPlacement.Bottom, Labels = new BitChartLegendLabelOptions { UsePointStyle = true } } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Linear, Placement = BitPlacement.Bottom,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Wavelength (nm)" } },
["x2"] = new BitChartScaleOptions { Id = "x2", Type = BitChartScaleType.Linear, Placement = BitPlacement.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) }
}
}
};
```
## Scales
Fixed and suggested ranges, step sizes, logarithmic and reversed axes, axes at the zero line, and grace.
\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**Axes at the zero line**:
```razor
```
```csharp
private readonly BitChartOptions _center = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } },
Scales =
{
["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Linear, Placement = BitPlacement.Center },
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, Placement = BitPlacement.Center }
}
};
private BitChartData Quadrants()
{
var rnd = new Random(11);
var pts = new List();
for (int i = 0; i < 40; i++)
pts.Add(new BitChartDataPoint(Math.Round(rnd.NextDouble() * 20 - 10, 2), Math.Round(rnd.NextDouble() * 20 - 10, 2)));
return new BitChartData
{
Datasets = { new BitChartDataset { Label = "Samples", Points = pts, BackgroundColor = "#9966ff", PointRadius = 5 } }
};
}
```
## Time
Time axes, with the unit picked automatically or forced with a format of its own.
\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)
```
## Titles
Chart titles and subtitles, where they go, and axis titles.
\n**Title and subtitle**:
```razor
```
```csharp
private readonly BitChartOptions _titled = new()
{
Plugins = new BitChartPluginOptions
{
Title = new BitChartTitleOptions { Display = true, Text = "Revenue by product" },
Subtitle = new BitChartTitleOptions
{
Display = true,
Text = "Thousands of euro, first seven months",
Font = new BitChartFont { Size = 12 },
Color = "var(--bit-clr-fg-sec)"
},
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom }
}
};
```
\n**Placement**:
```razor
```
```csharp
private BitPlacement _position = BitPlacement.Left;
private BitPlacement _align = BitPlacement.Center;
private BitChartOptions Placement() => new()
{
Plugins = new BitChartPluginOptions
{
Title = new BitChartTitleOptions { Display = true, Text = "Monthly sales", Placement = _position, Align = _align },
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom }
}
};
```
\n**Axis titles**:
```razor
```
```csharp
private readonly BitChartOptions _axisTitles = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } },
Scales =
{
["x"] = new BitChartScaleOptions
{
Id = "x", Type = BitChartScaleType.Category,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Month" }
},
["y"] = new BitChartScaleOptions
{
Id = "y", Type = BitChartScaleType.Linear, BeginAtZero = true,
Title = new BitChartScaleTitleOptions { Display = true, Text = "Units sold" }
}
}
};
```
## Legend
An interactive legend, its title, point-style markers and a cap on long legends.
\n**Interactive legend controls**:
```razor
@* Bind controls to legend options; the chart recomputes on each change. *@
Point style
Reverse
Highlight on hover
```
```csharp
private BitPlacement _position = BitPlacement.Top;
private BitPlacement _align = BitPlacement.Center;
private bool _usePointStyle;
private bool _reverse;
private bool _highlight = true;
private BitChartOptions Live() => new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions
{
Placement = _position, Align = _align, Reverse = _reverse, HighlightOnHover = _highlight,
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 { Placement = BitPlacement.Bottom, Title = "Product lines" }
}
};
// Revenue(): 3 datasets (Product A/B/C) over Jan..Jul
```
\n**Capping a long legend**:
```razor
```
```csharp
private readonly BitChartOptions _capped = new()
{
Plugins = new BitChartPluginOptions
{
// Past 120px the legend scrolls instead of pushing the plot out of the way.
Legend = new BitChartLegendOptions { Placement = BitPlacement.End, MaxHeight = 120 }
}
};
private BitChartData ManySeries()
{
var data = new BitChartData { Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" } };
for (int i = 0; i < 12; i++)
{
var values = Enumerable.Range(0, 7)
.Select(x => (double?)Math.Round(30 + i * 4 + Math.Sin((x + i) / 1.4) * 12, 1))
.ToList();
data.Datasets.Add(new BitChartDataset { Label = $"Region {i + 1}", Data = values, PointRadius = 0 });
}
return data;
}
```
## Tooltips
Tooltip callbacks for the title, the footer and the labels, currency formats, styling and point-style swatches.
\n**Title & footer callbacks**:
```razor
```
```csharp
private readonly BitChartOptions _footer = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.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 { Placement = BitPlacement.Bottom },
Tooltip = new BitChartTooltipOptions
{
Mode = BitChartInteractionMode.Index,
BackgroundColor = "#ffffff",
TitleColor = "#1f2733",
BodyColor = "#3a4452",
FooterColor = "#1f2733",
BorderColor = "#e0e4ea",
BorderWidth = 1,
TitleAlign = BitPlacement.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 { Placement = BitPlacement.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**Wrapping a longer note**:
```razor
```
```csharp
private readonly BitChartOptions _wrapped = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Tooltip = new BitChartTooltipOptions
{
// A width is what lets the box wrap; without one every row stays on a single line.
MaxWidth = 240,
Callbacks = new BitChartTooltipCallbacks
{
AfterBody = items => items.Count == 0
? null
: $"The index blends affordability, transit coverage and air quality, "
+ $"rebased so the median country reads 70. {items[0].Label} is "
+ $"{(items[0].Value >= 70 ? "above" : "below")} that median."
}
}
}
};
```
## Interaction
Hover and intersection modes, loading and empty states, and charts linked to each other.
\n**Hover anywhere**:
```razor
```
```csharp
// Intersect is false by default, so no extra configuration is needed.
private readonly BitChartOptions _default = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
private BitChartData Series() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Requests", Data = new() { 120, 190, 160, 250, 220, 300, 280 },
BorderColor = "#36a2eb", PointRadius = 0, Tension = 0.3 },
new BitChartDataset { Label = "Errors", Data = new() { 12, 9, 20, 14, 18, 11, 8 },
BorderColor = "#ff6384", PointRadius = 0, Tension = 0.3 }
}
};
```
\n**Require an intersection**:
```razor
```
```csharp
private readonly BitChartOptions _intersect = new()
{
Interaction = new BitChartInteractionOptions { Intersect = true },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
```
\n**Interaction modes**:
```razor
```
```csharp
private BitChartInteractionMode _mode = BitChartInteractionMode.Index;
private BitChartOptions ModeOptions() => new()
{
Interaction = new BitChartInteractionOptions { Mode = _mode },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
```
\n**Loading and empty states**:
```razor
Reload
@(_hasData ? "Clear the data" : "Restore the data")
```
```csharp
private bool _hasData = true;
private bool _loading;
private void ToggleEmpty() => _hasData = !_hasData;
private async Task Reload()
{
_loading = true;
await Task.Delay(1500); // stands in for fetching the data
_loading = false;
}
private BitChartData EmptyDemoData() => _hasData ? Revenue() : new BitChartData();
```
\n**Linked charts**:
```razor
```
```csharp
private string? _linked;
private readonly BitChartOptions _linkedOptions = new()
{
Interaction = new BitChartInteractionOptions { Mode = BitChartInteractionMode.Index },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
// Both charts report through here; a null context means the pointer has left.
private void Link(BitChartTooltipContext? context)
=> _linked = context is null
? null
: $"{context.Title}: " + string.Join(", ", context.Points.Select(p => $"{p.Label} {p.FormattedValue}"));
```
## Data labels
Values drawn on the data: on and inside bars, formatted on a line, percentages in a doughnut.
\n**Values on the bars**:
```razor
```
```csharp
private readonly BitChartOptions _outside = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
DataLabels = new BitChartDataLabelOptions
{
Display = true,
Anchor = BitPlacement.End,
Align = BitPlacement.End,
Font = new BitChartFont { Weight = "bold" }
}
},
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Display = false, Grace = 0.15 } }
};
private BitChartData Sales() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Units", Data = new() { 12, 19, 14, 22, 18, 25, 20 },
BackgroundColor = "#36a2eb", BorderRadius = 6 }
}
};
```
\n**Inside the bars**:
```razor
```
```csharp
private readonly BitChartOptions _inside = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
DataLabels = new BitChartDataLabelOptions
{
Display = true,
Anchor = BitPlacement.End,
Align = BitPlacement.Start,
Color = "#fff",
BackgroundColor = "rgba(0,0,0,0.35)",
Padding = 3,
Font = new BitChartFont { Weight = "bold" }
}
}
};
```
\n**Formatted labels on a line**:
```razor
```
```csharp
private readonly BitChartOptions _line = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
DataLabels = new BitChartDataLabelOptions
{
Display = true,
Offset = 6,
Formatter = v => $"{v:N0} k",
DisplayFn = (v, _, _) => v > 250
}
}
};
private BitChartData Traffic() => new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Visits", Data = new() { 120, 190, 260, 250, 320, 300, 280 },
BorderColor = "#4bc0c0", Tension = 0.35, PointRadius = 4 }
}
};
```
\n**Percentages in a doughnut**:
```razor
```
```csharp
private readonly BitChartOptions _doughnut = new()
{
CutoutPercentage = 55,
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.End },
DataLabels = new BitChartDataLabelOptions
{
Display = true,
Anchor = BitPlacement.Center,
Color = "#fff",
Font = new BitChartFont { Weight = "bold" },
FormatterCtx = (v, _, _) => $"{v / 1340d * 100:N0}%"
}
}
};
```
## Annotations
Threshold lines, boxes, vertical markers, ellipses, polygons and points drawn over the plot.
\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",
Description = "Low band: scores under 30", 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**Ellipse, polygon and point**:
```razor
```
```csharp
_shapes = new BitChartOptions
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Custom =
{
new BitChartAnnotationPlugin(
// An ellipse takes the same bounds a box does, and is inscribed in them.
new BitChartAnnotation
{
Kind = BitChartAnnotationKind.Ellipse, XIsIndex = true,
XMin = 4, XMax = 6, YMin = 65, YMax = 100,
Color = "#2ecc71", FillColor = "rgba(46,204,113,0.12)", Label = "Best run"
},
// A polygon is centered on one coordinate, sized in pixels, and points up by default.
new BitChartAnnotation
{
Kind = BitChartAnnotationKind.Polygon, XIsIndex = true,
XMin = 3, Value = 35, Sides = 3, Radius = 12,
Color = "#ff6384", Label = "Dip"
},
new BitChartAnnotation
{
Kind = BitChartAnnotationKind.Point, XIsIndex = true,
XMin = 1, Value = 45, Radius = 7, Color = "#9966ff"
}
)
}
}
};
```
## Trendlines
Linear regression lines, projections across the plot, moving averages and the mean.
\n**Linear regression**:
```razor
```
```csharp
private readonly BitChartOptions _linear = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom },
Custom = { new BitChartTrendlinePlugin(new BitChartTrendline { DatasetIndex = 0 }) }
}
};
private BitChartData Noisy() => new()
{
Labels = { "W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8", "W9", "W10", "W11", "W12" },
Datasets =
{
new BitChartDataset
{
Label = "Tickets closed",
Data = new() { 18, 26, 21, 33, 28, 39, 31, 44, 38, 51, 46, 57 },
BackgroundColor = "rgba(54,162,235,0.55)",
BorderColor = "#36a2eb",
BorderRadius = 4
}
}
};
```
\n**Projected across the plot**:
```razor
```
```csharp
private readonly BitChartOptions _extended = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom },
Custom =
{
new BitChartTrendlinePlugin(new BitChartTrendline
{
DatasetIndex = 0,
Extend = true, // run the fit out to both edges of the plot
Color = "#ff6384",
Label = "trend"
})
}
}
};
```
\n**Moving average and the mean**:
```razor
```
```csharp
private readonly BitChartOptions _averages = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom },
Custom =
{
new BitChartTrendlinePlugin(
new BitChartTrendline
{
DatasetIndex = 0,
Kind = BitChartTrendlineKind.MovingAverage,
Period = 4,
Color = "#9966ff",
Dash = null, // solid, so it reads as the smoothed series
Label = "4-week average"
},
new BitChartTrendline
{
DatasetIndex = 0,
Kind = BitChartTrendlineKind.Average,
Color = "#c9cbcf",
LineWidth = 1.5
})
}
}
};
private BitChartData Seasonal() => new()
{
Labels = { "W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8", "W9", "W10", "W11", "W12" },
Datasets =
{
new BitChartDataset
{
Label = "Orders",
Data = new() { 42, 61, 38, 70, 45, 78, 52, 84, 49, 90, 58, 96 },
BorderColor = "#4bc0c0",
BackgroundColor = "#4bc0c0",
PointRadius = 3
}
}
};
```
## Animations
How the bars grow and the lines draw on as a chart appears.
\n**Bars**:
```razor
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
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] } };
}
```
## Scriptable
Colors, radii and styles computed per data point: by sign, by threshold, by value or by parity.
\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
}
}
};
```
## Zoom & Pan
Zooming and panning: decimated lines, both axes, a drag-to-zoom box, category axes, and an overview beside the detail.
\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" } }
};
}
```
\n**Overview and detail**:
```razor
First quarter
Whole series
```
```csharp
private BitChart? _brush;
private BitChartData _brushData = default!;
private string _window = "the whole series";
private readonly BitChartOptions _brushOptions = new()
{
Plugins = new BitChartPluginOptions
{
Legend = new BitChartLegendOptions { Display = false },
Decimation = new BitChartDecimationOptions { Enabled = true, Samples = 250, Threshold = 400 }
},
Zoom = new BitChartZoomOptions { Enabled = true, Mode = BitChartZoomMode.X },
Scales = { ["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Time } }
};
private readonly BitChartOptions _overview = new()
{
Sparkline = true,
MaintainAspectRatio = false,
Plugins = new BitChartPluginOptions
{
Decimation = new BitChartDecimationOptions { Enabled = true, Samples = 250, Threshold = 400 },
Tooltip = new BitChartTooltipOptions { Enabled = false }
},
Scales = { ["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Time } }
};
// Zooms the detail chart to a fraction of the full series.
private void ShowWindow(double from, double to)
{
var points = _brushData.Datasets[0].Points!;
double min = points[0].X, span = points[^1].X - min;
_brush!.ZoomTo("x", min + span * from, min + span * to);
}
// OnZoomChange fires after every wheel, drag and ZoomTo, so the readout always matches the view.
private void ReadWindow()
{
// No range means nothing is zoomed - a reset leaves the readout claiming the old window otherwise.
if (_brush?.GetAxisRange("x") is not { } range)
{
_window = "the whole series";
return;
}
_window = $"{DateTime.FromOADate(range.Min):MMM d, HH:mm} to {DateTime.FromOADate(range.Max):MMM d, HH:mm}";
}
```
## Live data
Streaming data into a chart, and showing or hiding series from code.
\n**Streaming updates**:
```razor
@(_timer is null ? "Start" : "Stop")
Add one reading
```
```csharp
private const int WindowSize = 40;
private BitChart? _live;
private System.Timers.Timer? _timer;
// One data object, appended to in place - Refresh() is what makes the chart re-read it.
private readonly BitChartData _stream = new()
{
Datasets =
{
new BitChartDataset
{
Label = "Throughput",
BorderColor = "#36a2eb",
FillColor = "rgba(54,162,235,0.15)",
Fill = BitChartFillMode.Origin,
PointRadius = 0,
Tension = 0.3
}
}
};
// A live feed redraws several times a second, so the entry animation is turned off.
private readonly BitChartOptions _streamOptions = new()
{
Animation = new BitChartAnimationOptions { Animate = false },
Scales =
{
["y"] = new BitChartScaleOptions { Id = "y", Type = BitChartScaleType.Linear, BeginAtZero = true, SuggestedMax = 100 }
},
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private void Toggle()
{
if (_timer is not null) { Stop(); return; }
_timer = new System.Timers.Timer(700) { AutoReset = true };
_timer.Elapsed += async (_, _) => await InvokeAsync(AddReading);
_timer.Start();
}
private void AddReading()
{
Append(); // append one value, drop the oldest
_live?.Refresh(); // rebuild the scene from the data as it now stands
StateHasChanged();
}
```
\n**Showing and hiding series from code**:
```razor
@for (int i = 0; i < _revenue.Datasets.Count; i++)
{
var index = i;
}
Show all
```
```csharp
private BitChart? _visibility;
private readonly BitChartData _revenue = Revenue();
private readonly BitChartOptions _visibilityOptions = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
// The same state the legend drives:
// chart.ToggleDataset(i) / SetDatasetVisible(i, visible) / IsDatasetVisible(i)
// chart.ToggleDataIndex(i) for one pie/doughnut/polar-area slice
// chart.ResetVisibility() to bring everything back
```
## Localization
Culture-aware numbers, currency ticks, localized dates, non-Latin labels and right-to-left charts.
\n**Culture-aware numbers**:
```razor
```
```csharp
private string _culture = "de-DE";
private BitChartOptions CultureOptions() => new()
{
Culture = CultureInfo.GetCultureInfo(_culture),
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
```
\n**Currency ticks**:
```razor
```
```csharp
private readonly BitChartOptions _currency = new()
{
Culture = CultureInfo.GetCultureInfo("en-US"),
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } },
Scales = { ["y"] = new BitChartScaleOptions { Id = "y", Ticks = new BitChartTickOptions { Format = "C0" } } }
};
```
\n**Localized dates**:
```razor
```
```csharp
private string _dateCulture = "fr-FR";
// The culture drives the month and day names on a time axis as well as the numbers.
private BitChartOptions DateOptions() => new()
{
Culture = CultureInfo.GetCultureInfo(_dateCulture),
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } },
Scales = { ["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Time } }
};
```
\n**Non-Latin labels**:
```razor
```
```csharp
private readonly BitChartOptions _wide = new()
{
Culture = CultureInfo.GetCultureInfo("ja-JP"),
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } },
Scales =
{
["y"] = new BitChartScaleOptions
{
Id = "y",
Title = new BitChartScaleTitleOptions { Display = true, Text = "売上高(百万円)" }
}
}
};
private BitChartData Japanese() => new()
{
Labels = { "東京都", "大阪府", "愛知県", "福岡県", "北海道", "京都府" },
Datasets =
{
new BitChartDataset
{
Label = "今年度",
Data = new() { 320, 245, 198, 162, 140, 121 },
BackgroundColor = "#36a2eb",
BorderRadius = 4
}
}
};
```
\n**Right-to-left and translated strings**:
```razor
```
```csharp
private readonly BitChartStrings _persianStrings = new()
{
RoleDescription = "نمودار",
LegendAriaLabel = "راهنمای نمودار",
PositionFormat = "{0} از {1}",
SeriesPositionFormat = "سری {0} از {1}",
DatasetLabelFormat = "مجموعه {0}",
Series = "سری"
};
private readonly BitChartOptions _rtl = new()
{
Plugins = new BitChartPluginOptions
{
Title = new BitChartTitleOptions { Display = true, Text = "فروش فصلی" },
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom }
},
Scales = { ["x"] = new BitChartScaleOptions { Id = "x", Type = BitChartScaleType.Category, Reverse = true } }
};
private BitChartData Persian() => new()
{
Labels = { "بهار", "تابستان", "پاییز", "زمستان" },
Datasets =
{
new BitChartDataset { Label = "درآمد", Data = new() { 120, 190, 160, 250 }, BackgroundColor = "#4bc0c0", BorderRadius = 4 },
new BitChartDataset { Label = "هزینه", Data = new() { 80, 120, 110, 150 }, BackgroundColor = "#ff9f40", BorderRadius = 4 }
}
};
```
## Export
Downloading a chart as SVG, PNG or CSV, or taking the picture or the CSV without downloading anything.
\n**Download the chart**:
```razor
Download SVG
Download PNG
Download CSV
```
```csharp
private BitChart? _chart;
private readonly BitChartOptions _options = new()
{
Plugins = new BitChartPluginOptions
{
Title = new BitChartTitleOptions { Display = true, Text = "Revenue by product" },
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom }
}
};
private Task ExportSvg() => _chart!.ExportSvgAsync("revenue.svg");
// scale 2 renders at twice the on-screen size, which stays crisp on high-density displays.
private Task ExportPng() => _chart!.ExportPngAsync("revenue.png", scale: 2);
private Task ExportCsv() => _chart!.ExportCsvAsync("revenue.csv");
```
\n**The CSV without downloading it**:
```razor
Show the CSV
@if (_csv is not null)
{
```
```csharp
private BitChart? _csvChart;
private string? _csv;
private void ShowCsv() => _csv = _csvChart!.ToCsv();
```
\n**The picture without downloading it**:
```razor
Render to a data URL
Show the SVG markup
@if (_dataUrl is not null)
{
}
@if (_markup is not null)
{
```
```csharp
private BitChart? _imageChart;
private string? _dataUrl;
private string? _markup;
// scale 1 matches the on-screen size; pass 2 for a high-density snapshot.
private async Task ShowImage() => _dataUrl = await _imageChart!.ToBase64ImageAsync(scale: 1);
// The theme tokens the chart references are resolved into the markup, so it stands alone.
private async Task ShowMarkup() => _markup = await _imageChart!.ToSvgStringAsync();
```
## Accessibility
What keyboard and screen-reader users get from a chart.
\n**Keyboard and screen readers**:
```razor
```
```csharp
private bool _disabled;
private string? _selected;
private readonly BitChartData _data = new()
{
Labels = { "Q1", "Q2", "Q3", "Q4" },
Datasets =
{
new BitChartDataset { Label = "North", Data = { 42, 51, 48, 60 } },
new BitChartDataset { Label = "South", Data = { 35, 39, 46, 52 } }
}
};
private void Select((int DatasetIndex, int DataIndex) element)
=> _selected = $"Selected: {_data.Datasets[element.DatasetIndex].Label}, {_data.Labels[element.DataIndex]}";
```
## Customization
The CSS variables, cascading parameters, and Style & Class.
\n**CSS variables**:
```razor
```
```csharp
private const string _brandStyle =
"--bit-Chart-series-color-1: #7c3aed;" +
"--bit-Chart-series-color-2: #f59e0b;" +
"--bit-Chart-grid-color: rgba(124, 58, 237, 0.15);" +
"--bit-Chart-tick-color: #7c3aed;" +
"--bit-Chart-tooltip-background: #2e1065;" +
"--bit-Chart-tooltip-color: #f5f3ff;" +
"--bit-Chart-tooltip-radius: 12px;" +
"--bit-Chart-font-family: Georgia, serif;";
private readonly BitChartOptions _options = new()
{
Interaction = new BitChartInteractionOptions { Mode = BitChartInteractionMode.Index },
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom } }
};
// No colors in the data: the series take the palette, which the variables re-skin.
private readonly BitChartData _data = new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Visitors", Data = { 120, 190, 160, 250, 220, 300, 280 }, Tension = 0.4 },
new BitChartDataset { Label = "Signups", Data = { 40, 70, 55, 90, 85, 120, 110 }, Tension = 0.4 }
}
};
```
\n**Cascading parameters**:
```razor
```
```csharp
// One shared options instance: the renderer never writes back into it, so every chart can read it.
private static readonly BitChartOptions _sharedOptions = new()
{
Plugins = new BitChartPluginOptions { Legend = new BitChartLegendOptions { Display = false } }
};
private readonly BitChartParams[] _chartParams =
[
new()
{
Type = BitChartType.Bar,
Options = _sharedOptions,
Height = "160px",
Styles = new() { Root = "--bit-Chart-series-color-1: #0f766e; padding: 0.5rem; border-radius: 6px; background: var(--bit-clr-bg-sec);" }
}
];
private readonly BitChartData _north = Region("North", 42, 51, 48, 60);
private readonly BitChartData _south = Region("South", 35, 39, 46, 52);
private readonly BitChartData _west = Region("West", 28, 33, 41, 38);
private static BitChartData Region(string label, params double?[] values) => new()
{
Labels = { "Q1", "Q2", "Q3", "Q4" },
Datasets = { new BitChartDataset { Label = label, Data = [.. values] } }
};
```
\n**Style & Class**:
```razor
```
```csharp
private readonly BitChartOptions _titled = new()
{
Plugins = new BitChartPluginOptions
{
Title = new BitChartTitleOptions { Display = true, Text = "Traffic" },
Subtitle = new BitChartTitleOptions { Display = true, Text = "First half of the year" },
Legend = new BitChartLegendOptions { Placement = BitPlacement.Bottom }
}
};
private readonly BitChartClassStyles _styles = new()
{
Root = "padding: 1rem; border-radius: 8px; border: 1px solid var(--bit-clr-brd-sec);",
Title = "text-transform: uppercase; letter-spacing: 0.08em;",
Subtitle = "font-style: italic;",
LegendItem = "border: 1px solid var(--bit-clr-brd-sec); border-radius: 999px; padding: 2px 10px;",
Tooltip = "border: 1px solid var(--bit-clr-brd-sec);"
};
private readonly BitChartData _data = new()
{
Labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" },
Datasets =
{
new BitChartDataset { Label = "Visitors", Data = { 120, 190, 160, 250, 220, 300, 280 }, Tension = 0.4 },
new BitChartDataset { Label = "Signups", Data = { 40, 70, 55, 90, 85, 120, 110 }, Tension = 0.4 }
}
};
```
@tile.Caption
@tile.Value
@(_linked ?? "Hover either chart")
Showing @_window
@* The overview strip: the same series with nothing but the line. *@
@_csv}
@_markup}
@(_selected ?? "Press Enter on a bar")