bar-chart-web-component
v1.3.0
Published
A web component for displaying a bar chart
Readme
Bar Chart Web Component
A web component for creating bar charts on web pages.
Usage
Basics
In order to use the web component you will need to add the script file to your web page
<head>
...
<script src="node_modules/bar-chart-web-component/BarChart.js"></script>
...
</head>Then add a <bar-chart> element to your page containing one or more <data-series> elements
<bar-chart>
<data-series>
<data-point label="2025-Oct-01" value="2"></data-point>
<data-point label="2025-Oct-02" value="15"></data-point>
...
</data-series>
</bar-chart>You can add axis labels and ticks using the attributes
<bar-chart
dependent-axis-label="Commits Per Day"
dependent-axis-ticks="5"
independent-axis-label="October 2025"
>See also the Basic Example
Styling
By default <bar-chart> should pick up on your site's theme including dark/light mode if you use common css variable names in particular
--rule-color(used for the axis)--primary-text-color(used for the labels)--secondary-background-color(used for the chart background, defaults to transparent)--primary-accent-color(used for the color of the bars, defaults to a blue)
See Basic Example and Multi-Series Example
When you have multiple data series it is generally helpful to use different colors for each series. You can set the color of a data series using the color attribute on the <data-series> element which accepts any css color specification including named colors.
<data-series color="orange">See the Multi-Series Example
Sometimes you want your chart to stand out a bit more though. In this case you can select label, axis, background, and default bar color.
bar-chart {
--bar-chart-axis-color: #00F;
--bar-chart-label-color: #999;
--bar-chart-background-color: #FDF5E6;
--bar-chart-default-bar-color: orange;
}See Styled Example
Contributing
Got an idea or an improvement? I'd love to hear about it. The easy way to contribute would be to submit a pull request or open an issue on the project at https://codeberg.org/tkegan/bar-chart-web-component
License
No AI - 2-Clause BSD Style License
Author
Tom Egan
