Git Product home page Git Product logo

chartjs-chart-error-bars's Introduction

Chart.js Error Bars

License: MIT NPM Package Github Actions

Chart.js module for charting error bars plots. This plugin extends the several char types (bar, line, scatter, polarArea) with their error bar equivalent (barWithErrorBars, lineWithErrorBars, scatterWithErrorBars, polarAreaWithErrorBars).

Bar Chart

bar char with error bars

Horizontal Bar Chart

horizontal bar chart with error bars

Line Chart

line chart with error bars

Scatterplot

scatter plot with error bars

Polar Area plot

polar area plot with error bars

Related Plugins

Check out also my other chart.js plugins:

Install

npm install --save chart.js chartjs-chart-error-bars

Usage

see Examples

and Open in CodePen

Styling

Several new styling keys are added to the individual chart types

Data structure

The data structure depends on the chart type. It uses the fact that chart.js is supporting scatterplots. Thus, it is already prepared for object values.

Chart types: bar and line

see TypeScript Interface:

IErrorBarXDataPoint

Chart type: bar with indexAxis: 'y'

IErrorBarYDataPoint

Chart type: scatter

a combination of the previous two ones

IErrorBarXDataPoint

and

IErrorBarYDataPoint

Chart type: polarArea

IErrorBarRDataPoint

Multiple Error Bars

Multiple error bars are supported.

multiple error bars

Styling

The styling options support different array version.

Note: as with other chart.js style options, using an array will be one value per dataset. Thus, to specify the values for different error bars, one needs to wrap it in an object with a v key having the value itself. The outer for the dataset, the inner for the error bars.

see TypeScript interface:

IErrorBarOptions

Data structure

Just use array of numbers for the corresponding data structures attributes (xMin, xMax, yMin, yMax). The error bars will be rendered in reversed order. Thus, by convention the most inner error bar is in the first place.

e.g.

{
  y: 4,
  yMin: [2, 1],
  yMax: [5, 6]
}

ESM and Tree Shaking

The ESM build of the library supports tree shaking thus having no side effects. As a consequence the chart.js library won't be automatically manipulated nor new controllers automatically registered. One has to manually import and register them.

Variant A:

import Chart, { LinearScale, CategoryScale } from 'chart.js';
import { BarWithErrorBarsController, BarWithErrorBar } from 'chartjs-chart-error-bars';

// register controller in chart.js and ensure the defaults are set
Chart.register(BarWithErrorBarsController, BarWithErrorBar, LinearScale, CategoryScale);

const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
  type: BarWithErrorBarsController.id,
  data: {
    labels: ['A', 'B'],
    datasets: [
      {
        data: [
          {
            y: 4,
            yMin: 1,
            yMax: 6,
          },
          {
            y: 2,
            yMin: 1,
            yMax: 4,
          },
        ],
      },
    ],
  },
});

Variant B:

import { BarWithErrorBarsChart } from 'chartjs-chart-error-bars';

const chart = new BarWithErrorBarsChart(document.getElementById('canvas').getContext('2d'), {
  data: {
    //...
  },
});

Development Environment

npm i -g yarn
yarn install
yarn sdks vscode

Building

yarn install
yarn build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.