1.1.0 • Published 1 year ago

nhsd-dataviz v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

NHSD Data Visualisation Library

This is the repository for NHSD's data visualisation library.

The purpose of this library is create accessible data visualisations for web with HTML/SVG, JPG & PNG fallbacks where JavaScript isn't avaliable.


Getting Started

Download the latest release

To you can download the latest releases on the release page.

Build from source

Alternatively you may clone and build your own distribution:

git clone https://github.com/NHS-digital-website/nhsd-dataviz.git
npm install
npm run build

Usage

The following code snippet demonstrates loading the data visualisation library and creating a basic chart:

<html>
    <head>
      <script src="nhsd-dataviz.min.js"></script>
    </head>
    <body>
      <div id="viz"></div>
      <script>
      nhsdviz.chart('#viz', {
        "data": {
            "date": "2022",
            "percent": 18,
            "subject": "adults",
            "description": "had a possible eating disorder",
            "change": {
                "percent": -3,
                "date": "2021"
            }
        }
      });
      </script>
    </body>
</html>

API

Create a chart

nhsdviz.chart(selector, options)

# Options object

PropertyValueDescription
vizType"pie" | "doughnut" | "icon" | "stat" | "column"Chart type (default: pie)
titleStringChart title text
introTextStringChart introductory text
dataData objectChart data
source{ text: String, href: String }Source text
paletteStringChart palette
iconString (icon name)Chart icon
desktopViewportnumber (px)Desktop viewport (default: 1024)

# Data object

PropertyValueDescription
descriptionStringChart description
subjectStringData subject
change{ percent: number, from: number, date: string }Chart change text
yAxis{ title: string, start: number, end: number }yAxis options (column)
xAxis{ title: string }xAxis options (column)
percentnumberChart percent value (pie & doughnut)
ratio{ numerator: number, denominator: number }Chart ratio value (icon)
quantitynumberChart quantity value (stat)
series{ name: string, value: number }Chart series data (column)

# Supported icons

If building from source icons should be placed in the assets/icons/ directory, these icons can then be referenced by their file names.

If using the distribution library the following icons are avaliable:

  • arrow-down
  • arrow-up
  • calendar
  • invite
  • person
  • tooth
  • wine-glass

Examples

Pie Chart

https://jsfiddle.net/LEJA3/cq8rbs12/

Doughnut Chart

https://jsfiddle.net/LEJA3/f4o6v2xh/

Icon Chart

https://jsfiddle.net/LEJA3/kroLbf4z/

Statistics Chart

https://jsfiddle.net/LEJA3/rov9weby/

Column Chart

https://jsfiddle.net/LEJA3/fqtphz7o/


Colour palette

nhsdviz.createPalette(name, palette)

# Palette object

PropertyValueDescription
primaryString (Hex colour code)Primary chart colour
secondaryString (Hex colour code)Secondary chart colour
backgroundString (Hex colour code)Background chart colour
textString (Hex colour code)Main text colour
text2String (Hex colour code)Secondary text colour

Example

https://jsfiddle.net/LEJA3/k2tL0pcq/

1.1.0

1 year ago

1.0.8-rc.8

1 year ago

1.0.8-rc.7

1 year ago

1.0.2

2 years ago

1.0.8-rc.6

2 years ago

1.0.8-rc.5

2 years ago

1.0.8-rc.4

2 years ago

1.0.8-rc.3

2 years ago

1.0.8-rc.2

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.1

2 years ago