# animated-bars **Repository Path**: mirrors_olihawkins/animated-bars ## Basic Information - **Project Name**: animated-bars - **Description**: A JavaScript library for creating animated bar and column charts. - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2026-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # animated-bars __animated-bars__ is a JavaScript library for creating animated bar and column charts in webpages. The library exports two classes, `AnimatedBarChart` and `AnimatedColumnChart`, which differ in the orientation of their bars but which are functionally identical. Create a chart by providing some data and a configuration object. When you `update` a chart with new data, it animates a transition to the new values given the settings in the configuration. A chart can be `run` so that it steps through a sequence of different values at fixed intervals by providing an ES6 generator that yields new data each time it is called. The library uses [D3](https://d3js.org) to make the charts, but provides a high level interface so that you can use it on its own. However, the D3 selections used to create and run the chart are exposed in the chart object, so you can easily extend a chart's behaviour using D3 if you wish. Please note that while the library is functional it is not yet 1.0. Until then, its interfaces may evolve in response to feedback. ## Installation Install the library with `npm` for transpiling and bundling. ```bash npm install --save-dev animated-bars ``` Then import the classes you need in your code. ```javascript import { AnimatedColumnChart } from "animated-bars"; // Define config and data then ... const chart = new AnimatedColumnChart(data, config); ``` Alternatively, you can use the browser library directly in a webpage. Load `animated-bars.min.js` in a ` ``` The browser library can be found in the `dist` directory. ## Core principles The library aims to provide a simple and flexible interface to easily create and update animated bar and column charts. The interface is organised around some core ideas. Animated charts are instatiated with two components: some initial __data__ and a __config__. - __data__ is an array of objects representing data points, each of which must contain a __key__ and a __value__ property. These data point objects can optionally have other properties which specify how the chart should present indiviudal values. New `data` that is used to update a chart must have the same keys as the `data` that was used to create it. See the section on [data](#data) below for full details of data points and their properties. - __config__ is an object whose properties are used to configure the chart. The `config` object supports a number of properties that govern the chart's behaviour, but you only need to explicitly define properties that differ from the defaults. See [configuration](#configuration) below for full details of the properties that can be set in the `config` object, their default values, and the behaviour they control. The axes of a chart are described in terms of _keys_ and _values_ rather than _x_ and _y_: there is a __keyAxis__ and a __valueAxis__. This approach allows you to describe the structure of a chart independently of which way its bars are oriented. The same data and configuration will work for both bar and column charts, although different configurations may be more appropriate for one type than the other. ## Example usage A detailed set of examples showing how to use the library can be found in the `example` directory. You can see these examples running on the web [here](https://olihawkins.com/2019/09/1). The walkthrough below shows the basic steps needed to [create](#create-a-chart), [update](#update-a-chart), and [animate](#animate-a-chart-with-a-generator) a chart. ### Create a chart Let's create a simple animated column chart. The following example assumes you are working with `npm` but can be quickly adapted to work in the browser by following the slightly different setup instructions shown above. A version of this code using the browser library can be found in the `walkthrough` directory in `example`. Create a `