Code Monkey home page Code Monkey logo

chartjs-plugin-boxselect's Introduction

chartjs-plugin-boxselect

A Chart.js plugin to select points using click-and-drag boxes.
Works with scatter and line chart types.

Installation

To install with npm

npm install --save chartjs-plugin-boxselect

To use with a <script> tag

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-boxselect"></script>

Configuration

To configure the box-select plugin, add a new config option to a chart config.

plugins: {
    boxselect: {
        select: {
            enabled: true,
            direction: 'xy'
        },
        callbacks: {
            beforeSelect: function(startX, endX, startY, endY) {
                // return false to cancel selection
                return true;
            }
            afterSelect: function(startX, endX, startY, endY, datasets) {

            }
        }
    },
}

Options

The direction setting defines which box shapes can be drawn. The options are x, xy, or y. The default is xy.

The datasets parameter in the afterSelect callback is the same size as the array of datasets in the chart.
Each dataset has the parameters data, labels, and indexes.
data contains an array of points that fell inside the selection box.
indexes contains the corresponding index of each point that was selected from the original dataset.data labels contains the labels (if any) from the dataset that correspond to the selected points.

Samples

A sample chart that shows how the afterSelect callback can be used to highlight data is in the /samples directory.

Development

rollup is required to build.
The built boxselect.js file is in the /dist directory.
The build command is npm run build.

Credits

Created by Thomas Humphries.
Code inspired by chartjs-plugin-crosshair and chartjs-plugin-zoom.

Licence

chartjs-plugin-boxselect.js is available under the MIT licence.

chartjs-plugin-boxselect's People

Contributors

ericyoondotcom avatar tomhumphries avatar zachary822 avatar

Watchers

 avatar  avatar

Forkers

rajmohan27197

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.