Chart Types Lollipop Charts - wrathtafarian/js-charts GitHub Wiki

๐Ÿญ Lollipop Charts

A lollipop chart is a variation of a bar chart that uses a thin line with a circular marker at the end to represent data points. It is particularly useful for comparing discrete categories while maintaining a clean and visually appealing design. Lollipop charts work well when you want to emphasize the actual values while reducing visual clutter, making them a good alternative to traditional bar charts when space or aesthetics are a concern.

  • Usage: ๐Ÿงต Patterns ๐Ÿ” Comparison
  • Types:
    • Clustered Lollipop Bar Chart compares individual values across categories (horizontal lollipops).
    • Stacked Lollipop Bar Chart compares both the total value and the breakdown of categories (horizontal lollipops).
    • 100% Stacked Lollipop Bar Chart focuses on the percentage contribution of each sub-category, normalizing each bar to 100% (horizontal lollipops).
    • Clustered Lollipop Column Chart compares individual values across categories (vertical lollipops).
    • Stacked Lollipop Column Chart compares both the total value and the breakdown of categories (vertical lollipops).
    • 100% Stacked Lollipop Column Chart focuses on the percentage contribution of each sub-category, normalizing each bar to 100% (vertical lollipops).

These charts are best used for ranking or highlighting differences between values, especially when dealing with moderate-sized datasets. They are most effective when paired with sorted data, as the clear separation between markers helps viewers quickly interpret patterns and trends. However, for very large datasets, a bar chart might be preferable due to better readability.

๐Ÿ’ก See the js-chart-examples repo for many detailed examples of how to use and customize (style) different types of lollipop charts.

Example Lollipop Chart - default Style Template

image

Example Lollipop Chart - default Style Template with Customization

image

Example Lollipop Chart - darkweb Style Template

image

Example Lollipop Chart - default Style Template

image

โš ๏ธ Required Files

Lollipop Bar Charts, Stacked Lollipop Bar Charts and 100% Stacked Lollipop Bar Charts require the following files to render correctly.

Filename Purpose
js/js-chart-common.js JavaScript source code file containing config and common functions.
js/js-chart-bar.js JavaScript source code file containing functions specific to lollipop bar charts.
css/js-chart-common.css Cascading Style Sheet file containing common styling.
css/js-chart-bar.css Cascading Style Sheet file containing styling specific to lollipop bar charts.

Lollipop Column Charts, Stacked Lollipop Column Charts and 100% Stacked Lollipop Column Charts require the following files to render correctly.

Filename Purpose
js/js-chart-common.js JavaScript source code file containing config and common functions.
js/js-chart-column.js JavaScript source code file containing functions specific to lollipop column charts.
css/js-chart-common.css Cascading Style Sheet file containing common styling.
css/js-chart-column.css Cascading Style Sheet file containing styling specific to lollipop column charts.

โš™๏ธ Chart Attributes

Lollipop charts accept the following chart attributes.

๐Ÿงฑ class | ๐Ÿ—‚๏ธ type | ๐Ÿ•’ version | ๐Ÿ“‹ template | โ†”๏ธ width | โ†•๏ธ height | ๐Ÿ“„ title | ๐Ÿ“„ ytitle | ๐Ÿ“„ xtitle | ๐Ÿ“ scalemin | ๐Ÿ“ scalemax | ๐Ÿ”„ swapaxis | ๐Ÿ”ฝ sortdata | ๐Ÿšซ limitdata | ๐Ÿ”ฒ showborder | ๐Ÿท๏ธ showlabels | ๐Ÿ“˜ showlegend | ๐ŸŽฎ showcontrols | ๐Ÿ—‚๏ธ showdatatable | #๏ธโƒฃ showgridlines | โž– showzeroline | ๐Ÿ“ˆ showlines | ๐Ÿ“ showmarkers | ๐Ÿ“ฒ showwidget

๐Ÿงฑ Input Data

Category: ๐Ÿท๏ธ js-labels

The js-labels input container sets the labels that anchors each cluster on the axis (e.g., different months, regions, or items).

The container accepts a comma-separated list of text values.

<div class="js-labels">label-0, label-1, label-2, ..., label-n</div>

The example below sets the category labels on a chart to the months of the year.

<div class="js-labels">Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec</div>

Data Series: ๐Ÿ“‹ js-values

The js-values input container sets the individual data series (or data sets) on a chart.

The container accept a comma-separated list of numeric values.

<div class="js-values">10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120</div>

The js-values input container accepts a title attribute that is used to set a name or short description for the data series (or data set).

<div class="js-values" title="Sales revenue 2024">10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120</div>

โ„น๏ธ A title will automatically be assigned to each data series (or data set) if no title attribute is assigned to the js-values container.

Clustered data series (or multiple data series) can be set by specifying multiple js-values input containers. Each container represents a single data series (or data set).

<div class="js-values" title="Sales revenue 2024">20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130</div>
<div class="js-values" title="Sales revenue 2023">15, 25, 35, 45, 55, 65 75, 85, 95, 105, 115, 125</div>
<div class="js-values" title="Sales revenue 2022">10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120</div>

๐Ÿ–Œ๏ธ Style Directives

Every chart is customized (or styled) using one of the supported style templates.

Style directives are used to override the customization applied by the style template to each chart.

Lollipop charts support the following style directives.

๐Ÿ–ผ๏ธ js-canvas-* ๐Ÿ“Š js-chart-* ๐ŸŽจ js-color-* ๐Ÿ–ฑ๏ธ js-control-button-* ๐Ÿท๏ธ js-datalabel-* ๐Ÿ—‚๏ธ js-datatable-* ๐Ÿฆถ js-footer-* #๏ธโƒฃ js-grid-line-* ๐Ÿ“˜ js-legend-* ๐Ÿ“ js-marker-* ๐ŸŽฎ js-options-menu-* ๐Ÿ“ js-scale-* ๐Ÿ“„ js-title-* ๐Ÿ“ˆ js-value-line-* โž– js-zero-line-*

๐Ÿ’ก See the ๐Ÿ‘€ js-chart-examples repo for many detailed examples of how to use the style directives to customize a chart.

๐Ÿ‘€ Examples

๐Ÿ’ก See the js-chart-examples repo for many detailed examples of how to use different types of lollipop charts.

Example: Lollipop Column Chart: Monthly Revenue Comparison

The example below renders a clustered bar chart, showing Player Hit Points for a fictional player tournament.

<div class="js-chart" type="stacked lollipop bar" title="Player Hit points" ytitle="y-axis title" xtitle="x-axis title">
    <div class="js-labels">Player 1, Player 2, Player 4, Player 9, Player 14, Player 18, Player 21, Player 22, Player 24, Player 26</div>
    <div class="js-values" title="1P">7, 4, 7, 12, 4, 16, 20, 19, 3, 12</div>
    <div class="js-values" title="2P">24, 19, 10, 2, 4, 0, 18, 5, 17, 1</div>
    <div class="js-values" title="3P">0, 3, 8, 1, 13, 0, 3, 9, 4, 12</div>
    <div class="js-values" title="4P">8, 1, 4, 11, 21, 7, 2, 18, 10, 21</div>
    <div class="js-values" title="5P">10, 13, 4, 15, 18, 14, 18, 0, 1, 21</div>
    <div class="js-values" title="6P">19, 5, 12, 8, 10, 14, 2, 3, 1, 24</div>
    <div class="js-values" title="7P">0, 21, 15, 22, 16, 7, 0, 3, 4, 3</div>

    <div class="js-datalabel-width">25px</div>
    <div class="js-datalabel-font-size">9px</div>
</div>

Explained

Category: ๐Ÿท๏ธ js-labels

The js-labels input container sets the labels that anchor each cluster on the axis. In this example, each cluster represents one quarter in the year.

Data Series: ๐Ÿ“‹ js-values

There are three js-values input containers. Each container represents one data series (or data set) on the chart. In the example, each container represents one product line.

Customization: ๐Ÿ–Œ๏ธ Style Directives
  • The js-datalabel-width style directive sets the width of data labels on the chart. Each label will be rendered 25px wide.
  • The js-datalabel-font-size sets a font-size of 9px for all data labels on the chart.

๐Ÿ’ก See the js-chart-examples repo for many detailed examples of how to use different types of lollipop charts.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ