Skip to content

leey0818/chartjs-plugin-dragzone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chartjs-plugin-dragzone

npm

A Chart.js plugin to provide drag area selection. Compatible with Chart.js v3 (>= v1.0.0)

how to work

Installation

Install package with npm:

npm install chartjs-plugin-dragzone --save

Usage

import { Chart } from 'chart.js';
import ChartDragzone from 'chartjs-plugin-dragzone';

// Register the plugin to all charts
Chart.register(ChartDragzone);

// OR only to specific charts:
new Chart(ctx, {
  plugins: [ChartDragzone],
  options: {
    // ...
  }
});

Add plugin options to chart configuration.

plugins: {
  dragzone: {
    // Color the drag area
    color: 'rgba(70,146,202,0.3)',

    // This function calls the selected data after the drag is completed.
    // It is stored for each dataset.
    onDragSelection: function (datasets, chart) {
      const datas = datasets[0];
      alert('Selected data: ' + JSON.stringify(datas));
    }
  }
}

About

A Chart.js plugin to provide drag area selection.

Resources

License

Stars

Watchers

Forks

Packages

No packages published