Chart
Charts provide a flexible wrapper around Chart.js for building themed data visualizations. Use this component for advanced configuration such as mixed chart types, custom plugins, and direct Chart.js instance access.
-
Pro Components -
Responsive Layout Tools -
Ever-Growing Pattern Library -
Unlimited Hosted Projects -
Pre-Built Pro Themes -
Pro Theme Builder -
Pro Color Tools -
Official Figma Design Kit Newer additions to Web Awesome, like <wa-toast>, aren't included in the currently available kit, but a new version is in the works.
Track its progress on GitHub. -
WA Pro Perpetual License -
Actual Human™ Support
Already have Pro? Log in
Web Awesome charts are built on Chart.js, an open source JavaScript charting library. They wrap Chart.js with opinionated defaults, automatic theming through CSS custom properties, and a simplified API that makes data visualization accessible with minimal configuration. Charts automatically adapt to light and dark modes with no extra code.
Web Awesome provides a dedicated element for each chart type:
| Chart | Best for |
|---|---|
| Bar Chart | Comparing quantities across categories |
| Line Chart | Trends over time |
| Pie Chart | Proportions of a whole |
| Doughnut Chart | Proportions with a hollow center |
| Radar Chart | Comparing several attributes at once |
| Polar Area Chart | Magnitudes across cyclical categories |
| Scatter Chart | Correlation between two variables |
| Bubble Chart | Correlation with a third variable as size |
Examples
Chart Types
The wa-chart element supports all Chart.js types by setting type in the config. Web Awesome also provides dedicated elements for each type — such as <wa-bar-chart>, <wa-line-chart>, and <wa-pie-chart> — that set the type automatically.
Providing Data with JSON
The simplest way to provide chart data is with a <script type="application/json"> tag inside the component. The JSON follows the Chart.js configuration format.
Providing Data with JavaScript
Set the config property from JavaScript when your data comes from code rather than static markup. The chart re-renders automatically each time you assign it. For data that updates at runtime, try the live controls in Accessing the Chart.js Instance.
config is shallowly reactive.
If you mutate the object in place, reassign it to trigger a re-render.
Theming
Charts use six pairs of CSS custom properties for dataset colors: --fill-color-1 through --fill-color-6 for backgrounds and --border-color-1 through --border-color-6 for borders. Background colors default to semi-transparent fills using color-mix(), while border colors default to the solid variant of each color. The --grid-color property controls the color of grid lines and axis borders.
Override them to apply a custom color palette.
The palette updates live. The chart re-renders whenever its resolved colors change, so swapping the palette below recolors it with no extra code.
Dark Mode
Charts respond to theme changes automatically. Because their colors resolve from CSS custom properties, switching between light and dark mode re-renders the chart with updated colors. No extra code is required. Use the theme toggle in any example's toolbar to preview a chart in dark mode.
Using CSS Variables in Data
You can use CSS variables such as var(--wa-color-*) and color-mix() directly in dataset backgroundColor and borderColor values. The component resolves these automatically at render time.
Legend Position
Use the legend-position attribute to control where the legend appears. Supported values include top (default), bottom, left, right, start, and end. The start and end values are direction-aware and will flip in RTL layouts.
Axis Labels
Use the x-label and y-label attributes to add labels to the chart axes.
Axis Range
Use the min and max attributes to constrain the value axis.
Grid Lines
Use the grid attribute to control which axes show grid lines. Options are both (default), x, y, and none.
Stacked Data
Use the stacked attribute to stack datasets on top of each other instead of placing them side by side.
Disabling Features
Use without-animation to disable transitions, without-legend to hide the legend, and without-tooltip to remove hover tooltips.
Custom Tooltips
By default, tooltips use the standard Chart.js text. That reads well for labeled charts, but scatter and bubble charts fall back to raw x, y coordinates. Format the text yourself with tooltip callbacks: return a string from callbacks.label to control each row, or from callbacks.title for the header.
Mixed Charts
Use the wa-chart element directly to combine different chart types in a single visualization. Set the type on each dataset to control how it renders.
Accessing the Chart.js Instance
After the chart renders, the underlying Chart.js instance is available on the chart property, whether you supplied data as JSON or through the config property. Use it for programmatic updates, exporting images, or any Chart.js API method. The controls below mutate chart.data and call chart.update() to add, remove, and randomize points live.
Using Plugins
Pass Chart.js plugins through the plugins property. A plugin is an object with an id and one or more hook methods. This example draws a dashed target line across the chart by hooking into afterDraw.
Accessibility Considerations
Charts are rendered on a <canvas> element, which is not accessible to screen readers by default. Web Awesome addresses this with two built-in attributes.
Use label to give the chart a short, descriptive name. This maps to aria-label on the canvas with role="img", which is the pattern recommended by Chart.js and ARIA authoring guidelines. Use description for a longer explanation of what the chart shows, ideally including the key insight or takeaway, not just a restatement of the chart type. A description like "Sales grew 40% quarter over quarter, with Q4 reaching a record $710K" is more useful than "A bar chart with four bars."
For complex charts where the underlying numbers matter, consider including a visually-hidden or expandable data table alongside the chart. The canvas element cannot expose tabular data to screen readers, so a table is the most reliable way to make precise values available when necessary.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/chart/chart.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/chart/chart.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/chart/chart.js';
To import this component for React 18 or below, use the following code:
import WaChart from '@awesome.me/webawesome/dist/react/chart/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | An optional <script type="application/json"> element containing the Chart.js configuration object. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
config |
The Chart.js configuration object. Setting this property will automatically re-render the chart.
Type
ChartJS['config']
|
|
descriptiondescription |
A description of the chart, used for accessibility.
Type
string | null
Default
null
|
|
gridgrid |
Which axes to show grid lines on.
Type
'x' | 'y' | 'both' | 'none'
Default
'both'
|
|
indexAxisindex-axis |
The base axis of the dataset. 'x' for vertical bars and 'y' for horizontal bars.
Type
'x' | 'y'
Default
'x'
|
|
labellabel |
A label for the chart, used for accessibility.
Type
string | null
Default
null
|
|
legendPositionlegend-position |
The position of the legend relative to the chart.
Type
LayoutPosition | 'start' | 'end'
Default
'top'
|
|
maxmax |
The maximum value for the value axis.
Type
number | null
Default
null
|
|
minmin |
The minimum value for the value axis.
Type
number | null
Default
null
|
|
pluginsplugins |
Additional Chart.js plugins to register for this chart instance.
Type
array
Default
[]
|
|
stackedstacked |
Stacks datasets on top of each other along the value axis.
Type
boolean
Default
false
|
|
typetype |
The type of chart to render. Valid types include
bar, line, pie, doughnut, polarArea, radar, scatter,
and bubble.
Type
ChartType
Default
'bar'
|
|
withoutAnimationwithout-animation |
Disables chart animations
Type
boolean
Default
false
|
|
withoutLegendwithout-legend |
Hides the legend
Type
boolean
Default
false
|
|
withoutTooltipwithout-tooltip |
Hides tooltips over data points
Type
boolean
Default
false
|
|
xLabelx-label |
A label for the x-axis.
Type
string | null
Default
null
|
|
yLabely-label |
A label for the y-axis.
Type
string | null
Default
null
|
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--border-color-1 |
Border color for the first dataset.
Default
var(--wa-color-blue-60)
|
--border-color-2 |
Border color for the second dataset.
Default
var(--wa-color-pink-60)
|
--border-color-3 |
Border color for the third dataset.
Default
var(--wa-color-green-60)
|
--border-color-4 |
Border color for the fourth dataset.
Default
var(--wa-color-yellow-60)
|
--border-color-5 |
Border color for the fifth dataset.
Default
var(--wa-color-purple-60)
|
--border-color-6 |
Border color for the sixth dataset.
Default
var(--wa-color-orange-60)
|
--border-radius |
Border radius for bar charts.
Default
var(--wa-border-radius-s)
|
--border-width |
Border width for bars and arcs.
Default
var(--wa-border-width-s)
|
--fill-color-1 |
Fill color for the first dataset.
Default
color-mix(in srgb, var(--wa-color-blue-60) 40%, transparent)
|
--fill-color-2 |
Fill color for the second dataset.
Default
color-mix(in srgb, var(--wa-color-pink-60) 40%, transparent)
|
--fill-color-3 |
Fill color for the third dataset.
Default
color-mix(in srgb, var(--wa-color-green-60) 40%, transparent)
|
--fill-color-4 |
Fill color for the fourth dataset.
Default
color-mix(in srgb, var(--wa-color-yellow-60) 40%, transparent)
|
--fill-color-5 |
Fill color for the fifth dataset.
Default
color-mix(in srgb, var(--wa-color-purple-60) 40%, transparent)
|
--fill-color-6 |
Fill color for the sixth dataset.
Default
color-mix(in srgb, var(--wa-color-orange-60) 40%, transparent)
|
--grid-border-width |
Border width for chart grid lines and axis borders.
Default
var(--wa-border-width-s)
|
--grid-color |
Color of the chart grid lines and axis borders.
Default
var(--wa-color-neutral-border-quiet)
|
--line-border-width |
Border width for line and radar charts.
Default
var(--wa-border-width-m)
|
--point-radius |
Radius of data point dots.
Default
var(--wa-border-width-m)
|
SSR
Learn more about Server-Side Rendering (SSR).
<wa-chart> uses chart.js to render into a <canvas> element, which has no server-side equivalent. The component reserves the expected space to prevent layout shift during SSR, but its contents won't draw until it hydrates on the client.