Chart.js Plugin for showing error bars for various chart types

Overview

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, horizontalBar, 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 Samples on Github

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 from 'chart.js';
import { BarWithErrorBarsController, RectangleWithErrorBar } from 'chartjs-chart-error-bars';

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

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
Comments
  • Uncaught Error:

    Uncaught Error: "barWithErrorBars" is not a registered controller (v3.9.1)

    When I import the plugin while using this with react-chartjs-2 i get the error below

    Uncaught Error: "barWithErrorBars" is not a registered controller.
        at Registry._get (chart.esm.js:4916:13)
        at Registry.getController (chart.esm.js:4862:17)
        at Chart.buildOrUpdateControllers (chart.esm.js:5610:42)
        at Chart.update (chart.esm.js:5644:33)
        at new Chart (chart.esm.js:5426:12)
        at renderChart (chart.tsx:42:24)
        at chart.tsx:98:5
        at invokePassiveEffectCreate (react-dom.development.js:23487:20)
        at HTMLUnknownElement.callCallback2 (react-dom.development.js:3945:14)
        at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:16)
    

    looking through the getController function i see that these are registered:

    pointWithErrorBar plugin
    barWithErrorBars plugin
    barWithErrorBar plugin
    pointWithErrorBar plugin
    barWithErrorBars plugin
    barWithErrorBar plugin
    pointWithErrorBar plugin
    barWithErrorBars plugin
    barWithErrorBar plugin
    barWithErrorBars controller throws
    

    To Reproduce

    that's a rough code (not complete, but the essentials are here)

    import { ChartData, ChartOptions, Point, Chart as ChartJS, BarControllerChartOptions } from 'chart.js';
    import {
      BarWithErrorBar,
      BarWithErrorBarsController,
      PointWithErrorBar,
      BarWithErrorBarsChart,
    } from 'chartjs-chart-error-bars';
    
    // these all registers i tries to add
    ChartJS.register(
      PointWithErrorBar,
      BarWithErrorBarsController,
      BarWithErrorBar,
      BarWithErrorBarsChart,
      LinearScale,
      CategoryScale,
      BarElement,
      LinearScale,
      PointElement,
      LineElement,
      TimeScale,
      CategoryScale,
      Title,
      Tooltip,
      Legend,
      Decimation,
      Tooltip,
      Legend,
      annotationPlugin
    );
    
    const options = {
                annotations,
                scales: {
                  x: {
                    type: 'time',
                    ticks: {
                      source: 'auto',
                    },
                  },
                  y: {
                    suggestedMin: 0,
                  },
                },
              };
    
    const getChartDatasets = (data:IErrorBarXYDataPoint[]): ChartData<'barWithErrorBars'> => ({
      labels: data.map(({ x }) => x),
      datasets: [
        {
          data,
        },
      ],
    });
    
    
    const BarChartWithErrors = () => {
    return <Chart
            type="barWithErrorBars"
            data={chartDatasets}
            options={chartOptions}
            plugins={[chartUtils.backgroundPlugin]}
          />
    }
    

    Expected behavior after registering BarWithErrorBarsController i expect it to not throw saying it's not registered

    Screenshots image

    Context

    • Version: latest
    • Browser: chrome latest
        "chart.js": "3.9.1",
        "chartjs-adapter-dayjs-3": "1.2.3",
        "chartjs-chart-error-bars": "3.9.0",
        "chartjs-plugin-annotation": "1.4.0",
        "react-chartjs-2": "4.3.1",
    
    bug help wanted 
    opened by AlonMiz 5
  • lineWithErrorBars

    lineWithErrorBars

    Hi Team, We are facing issue to create Line chart with error bars(lineWithErrorBars). We are getting issue with canvas context issue s undefined, Where same configuration working with barWithErrorBars. So if possible can you provide the reference code for lineWithErrorBars . We are using chart js 3.6.0 version and chartjs-chart-error-bars/v/3.6.0 version. above mentioned npm packges we are using with angular 12.

    Thanks, M.dev

    help wanted question 
    opened by mahadev-Pandhare 5
  • elements.point configurations does not apply in lineWithErrorBars

    elements.point configurations does not apply in lineWithErrorBars

    I,m using lineWithErrorBars, and when I try to set elements.point configs both locally on chart object and through Chart.defaults it seems that desired configuration does not apply.

    To Reproduce

    Chart.defaults.elements.point.radius = 10
    
    //or
    
    new Chart(document.getElementById('canvas').getContext('2d'), {
                type: 'lineWithErrorBars',
                options: {
                    elements: {
                        point:{
                            radius: 10
                        }
                    }
                },
                data: {
                    labels: labels,
                    datasets: datasets
                },
            });
    
    

    Context

    Thank you in advance for your great work.

    bug 
    opened by mohoma 4
  • Sample documentation for styling

    Sample documentation for styling

    Hello,

    could you add a styling example in the documentation ? I'm not fluent using ChartJS and I didn't manage to style error bars, where should I put the configuration options ?

    question 
    opened by papylhomme 4
  • Setting animation to false breaks line and scatter error bars

    Setting animation to false breaks line and scatter error bars

    When I set animation: false on line and scatter charts, error bars aren't drawn.

    To Reproduce

    1. Visit the CodePen: https://codepen.io/mossymaker/pen/zYRmwPP2.
    2. Toggle the animation option.

    Expected behavior

    Error bars render without animation.

    Context

    • Version: chartjs@3, chartjs-chart-error-bars@3
    • Browser: Safari 15.5; also happens on Chrome

    Additional context

    bug 
    opened by mossymaker 3
  • Bump ini from 1.3.5 to 1.3.7

    Bump ini from 1.3.5 to 1.3.7

    Bumps ini from 1.3.5 to 1.3.7.

    Commits
    • c74c8af 1.3.7
    • 024b8b5 update deps, add linting
    • 032fbaf Use Object.create(null) to avoid default object property hazards
    • 2da9039 1.3.6
    • cfea636 better git push script, before publish instead of after
    • 56d2805 do not allow invalid hazardous string as section name
    • See full diff in compare view
    Maintainer changes

    This version was pushed to npm by isaacs, a new releaser for ini since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 2
  • Updating a dataset without ErrorBar still draws the ErrorBars

    Updating a dataset without ErrorBar still draws the ErrorBars

    Hi, If I create a chart with error bars and then update the data with a simple array of values the error bars still show: https://codepen.io/dream_falcon/pen/OJveqKJ

    Is this a bug or I'm missing something? I don't want to destroy and redraw the chart because that is causing flickering in my react app.

    bug 
    opened by dreamfalcon 1
  • Removing y-axis labels

    Removing y-axis labels

    I'm trying to remove the y-label axes with the "scatterWithErrorBars". I tried some solution I found on SO, but none of them worked, so was thinking it was because this was more specific to the errorBar code?

    This is what it looks like now: image

    This is what I want it to look like: image

    here's my code:

    function generateErrorBarChart(min, max, meas, paramName, id) {
        let minimum = parseFloat(toFixed(min, 2));
        let maximum = parseFloat(toFixed(max, 2));
        let measured = parseFloat(toFixed(meas, 2));
    
        if (maximum < minimum && maximum == 0) {
            maximum = minimum + 1000;
        }
    
        new Chart(document.getElementById(id).getContext('2d'), {
            type: 'scatterWithErrorBars',
            options: options,
            data: {
                labels: [paramName],
                datasets: [
                    {
                        data: [
                            {
                                x: minimum,
                                y: 0,
                                xMin: minimum,
                                xMax: maximum,
                            },
                            {
                                x: maximum,
                                y: 0,
                                xMin: minimum,
                                xMax: maximum,
                            },
                            {
                                x: measured,
                                y: 0,
                            }
                        ],
                        fill: true,
                        borderColor: 'rgb(255, 0, 0)',
                        tension: 0.8
                    },
                ]
            },
        });
    }
    
    var options =
    {
        plugins: {
            legend: {
                display: false
            }
        }
    };
    
    
    function toFixed(value, precision) {
        var precision = precision || 0,
            power = Math.pow(10, precision),
            absValue = Math.abs(Math.round(value * power)),
            result = (value < 0 ? '-' : '') + String(Math.floor(absValue / power));
    
        if (precision > 0) {
            var fraction = String(absValue % power),
                padding = new Array(Math.max(precision - fraction.length, 0) + 1).join('0');
            result += '.' + padding + fraction;
        }
        return result;
    }
    
    question answered 
    opened by davlovsky 1
  • Error:

    Error: "barWithErrorBars" is not a chart type.

    I am trying to include the library in my application built in vue, but when I try to add the graphic with type: "barWithErrorBars" I get the mentioned error.

    I have these versions in my package.json: "chart.js": "^ 2.9.4", "chartjs-chart-error-bars": "^ 1.2.1", "vue": "^ 2.5.2",


    This is my component:

    <template>
      <canvas id="canvas"></canvas>
    </template>
    
    <script>
    import Chart from 'chart.js'
    export default {
      name: 'ErrorBar',
      mounted () {
        let chart = new Chart(document.getElementById('canvas').getContext('2d'), {
          type: 'barWithErrorBars',
          data: {
            labels: ['A', 'B'],
            datasets: [
              {
                data: [
                  {
                    y: 4,
                    yMin: 1,
                    yMax: 6
                  },
                  {
                    y: 2,
                    yMin: 1,
                    yMax: 4
                  }
                ]
              }
            ]
          },
          options: {
            scales: {
              yAxes: [
                {
                  ticks: {
                    beginAtZero: true
                  }
                }
              ]
            }
          }
        })
        return chart
      }
    }
    </script>
    
    <style scoped>
    canvas {
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }
    </style>
    

    Am I doing something wrong?

    Could you please help me?

    Thanks!

    question esm import 
    opened by Maitesz 1
  • ie11 compatibility

    ie11 compatibility

    Describe the bug When I try to use chartjs error bar library on ec2 (centOS) in AWS with IE11, I get the following error: Object doesn't support property or method 'assign'. But I do not get this issue with Google Chrome or Firefox.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    bug 
    opened by shraddha0110 1
  • Line with error bars fails for linear scale

    Line with error bars fails for linear scale

    When I use a linear scale and a lineWithErrorBars chart, nothing is drawn. Works fine for category scales.

    To Reproduce

    1. Navigate to https://codepen.io/mossymaker/pen/zYRmwPP2.

    Expected behavior

    Line with error bars is drawn on a linear scale.

    Screenshots

    image

    Context

    • Version: 3
    • Browser: Safari 15.6.1

    Additional context

    There's a comment in the Pen to toggle between the scale types. Here's the config I used:

    new Chart(document.getElementById('canvas').getContext('2d'), {
      type: 'lineWithErrorBars',
      data: {
        datasets: [
          {
            data: [
              {
                x: 1,
                y: 4,
                yMin: 1,
                yMax: 6,
              },
              {
                x: 2,
                y: 2,
                yMin: 1,
                yMax: 4,
              },
            ],
          },
        ],
      },
      options: {
        animation: false,
        scales: {
          // x: {
          //   type: 'category',
          //   labels: ['A', 'B']
          // },
          x: { type: 'linear'}
        },
      },
    });
    
    bug 
    opened by mossymaker 0
Releases(v4.1.0)
Owner
Samuel Gratzl
Research Software Engineer with a focus on Data Visualization - author of @lineupjs and @upsetjs
Samuel Gratzl
Chart.js plugin to defer initial chart updates

Chart.js plugin to defer initial chart updates until the user scrolls and the canvas appears inside the viewport, and thus trigger the initial chart a

Chart.js 97 Nov 9, 2022
A Simple Dashboard Chart in Laravel Nova using Chart JS

A Simple Dashboard Chart in Laravel Nova using Chart JS. Starting create your own dashboard with Chart JS Integration can save your time and help you maintain consistency across standard elements such as Bar, Stacked, Line, Area, Doughnut and Pie Chart.

Kuncoro Wicaksono 177 Jan 4, 2023
Bar Funnel Chart extension for Chart.js

Chart.BarFunnel.js Provides a Bar Funnel Chart for use with Chart.js Documentation To create a Bar Funnel Chart, include Chart.BarFunnel.js after Char

Chart.js 58 Nov 24, 2022
TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies

TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies; use it with any framework or backend.

null 24 Dec 12, 2022
Repo for various Tesla internal data visualizations

teslarender Repo for various Tesla internal data visualizations $ http-server -g -c0 -p8899 Access at: http://localhost:8899/?http://fn.lc/s/depthre

Tristan Rice 29 Dec 15, 2022
A simple tool to help you connect your favorite controllers / Arduino to various train simulator games on Windows using memory hacks.

A simple tool to help you connect your favorite controllers (e.g. Densha de Go! series) / Arduino to various train simulator games on Windows using memory hacks.

Tongze Wang 2 Feb 7, 2022
Zoom and pan plugin for Chart.js

chartjs-plugin-zoom A zoom and pan plugin for Chart.js >= 3.0.0 For Chart.js 2.6.0 to 2.9.x support, use version 0.7.7 of this plugin. Panning can be

Chart.js 510 Jan 2, 2023
Chart.js plugin for more styling options

chartjs-plugin-style Chart.js plugin for more styling options This plugin requires Chart.js 2.6.0 or later. Installation You can download the latest v

Akihiko Kusanagi 57 Oct 27, 2022
Chart.js plugin for live streaming data

chartjs-plugin-streaming Chart.js plugin for live streaming data chartjs-plugin-streaming 2.x requires Chart.js 3.0.0 or later. If you need Chart.js 2

Akihiko Kusanagi 401 Dec 27, 2022
Chart.js plugin to create charts with a hand-drawn, sketchy, appearance

chartjs-plugin-rough Chart.js plugin to create charts with a hand-drawn, sketchy, appearance Version 0.2 requires Chart.js 2.7.0 or later, and Rough.j

Akihiko Kusanagi 73 Dec 1, 2022
Chart.js plugin to calculate and draw statistical linear, exponential, power, logarithmic, and polynomial regressions.

chartjs-plugin-regression Chart.js plugin to calculate and draw statistical linear, exponential, power, logarithmic, and polynomial regressions using

Wilfredo Pomier 14 Dec 18, 2022
Draggable data points plugin for Chart.js

chartjs-plugin-dragdata.js Now compatible with Chart.js v3 ?? Looking for a version compatible to Chart.js < 2.9.x? Then visit the v2 branch! A plugin

Christoph Pahmeyer 196 Dec 18, 2022
Chart.js plugin for Prometheus data loading

Welcome to chartjs-plugin-datasource-prometheus ?? A Prometheus datasource for ChartJS. Dependencies: requires chart.js 2.7 or later. requires moment.

Samuel Berthe 77 Dec 6, 2022
Chart.js plugin to display labels on data elements

Overview Highly customizable Chart.js plugin that displays labels on data for any type of charts. Requires Chart.js 3.x. Documentation Introduction Ge

Chart.js 753 Dec 24, 2022
Annotation plugin for Chart.js

chartjs-plugin-annotation.js An annotation plugin for Chart.js >= 3.0.0 This plugin needs to be registered. It does not function as inline plugin. For

Chart.js 515 Dec 30, 2022
Redefined chart library built with React and D3

Recharts Introduction Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write charts i

recharts 19.4k Jan 2, 2023
:bar_chart: A D3-based reusable chart library

c3 c3 is a D3-based reusable chart library that enables deeper integration of charts into web applications. Follow the link for more information: http

C3.js 9.2k Jan 2, 2023
GPL version of Javascript Gantt Chart

dhtmlxGantt Getting started | Features | Follow us | License | Useful links dhtmlxGantt is an open source JavaScript Gantt chart that helps you illust

null 952 Dec 29, 2022
🍞📊 Beautiful chart for data visualization.

?? ?? Spread your data on TOAST UI Chart. TOAST UI Chart is Beautiful Statistical Data Visualization library. ?? Packages The functionality of TOAST U

NHN 5.2k Jan 2, 2023