Author: | KikyTokamuro |
---|---|
Views Total: | 303 views |
Official Page: | Go to website |
Last Update: | September 4, 2022 |
License: | MIT |
Preview:

Description:
The Segmented Horizontal Bar Graph is a graph type that displays percentages in terms of segments of a given length within a specified interval.
It is used to visualize and compare multiple data sets. The data is put into a set of bars, each of them representing a single data point.
In this post, I’d like to share you with a vanilla JavaScript library that helps you build this type of chart using plain HTML, CSS, and JavaScript. Let’s get started.
How to use it:
1. Load the stylesheet liner-bar.css and JavaScript liner-bar.js in the document.
<link rel="stylesheet" href="liner-bar.css" /> <script src="liner-bar.js"></script>
2. Create a container to hold the segmented bar graph.
<div id="liner-bar"> </div>
3. Prepare your data containing names, values, and background colors as follows:
const myData = [ { name: "CSS", value: 50, color: "#222" }, { name: "Script", value: 60, color: "#333" }, { name: "Com", value: 30, color: "#444" }, // ... ]
4. Initialize the liner-bar.js.
const myChart = new LinerBar("#liner-bar", { title: "My Chart", items: data, });
5. Render the segmented bar graph on the page.
myChart.render();
6. Enable the built-in dark mode.
const myChart = new LinerBar("#liner-bar", { title: "My Chart", items: data, dark: true, });
Changelog:
09/04/2022
- Fix bug in multiple liner-bars