]> git.argeo.org Git - gpl/argeo-suite.git/blob - js/src/chart/ChartJsPart.js
Revert loading of XSD
[gpl/argeo-suite.git] / js / src / chart / ChartJsPart.js
1 import ChartPart from './ChartPart.js';
2
3 import { Chart } from 'chart.js';
4 import annotationPlugin from 'chartjs-plugin-annotation';
5
6 Chart.register(annotationPlugin);
7
8 export default class ChartJsPart extends ChartPart {
9 #chart;
10
11 /** Constructor taking the mapName as an argument. */
12 constructor(chartName) {
13 super(chartName);
14 }
15
16 setChart(chart) {
17 this.#chart = chart;
18 }
19
20 getChart() {
21 return this.#chart;
22 }
23
24 //
25 // DATA
26 //
27 setLabels(labels) {
28 const chart = this.getChart();
29 chart.data.labels = labels;
30 this.update();
31 }
32
33 addDataset(label, data) {
34 const chart = this.getChart();
35 chart.data.datasets.push({
36 label: label,
37 data: data,
38 borderWidth: 1
39 });
40 this.update();
41 }
42
43 setData(labels, label, data) {
44 this.clearDatasets();
45 this.setLabels(labels);
46 this.addDataset(label, data);
47 }
48
49 setDatasets(labels, datasets) {
50 const chart = this.getChart();
51 chart.data.datasets = datasets;
52 chart.data.labels = labels;
53 this.update();
54 }
55
56 clearDatasets() {
57 const chart = this.getChart();
58 chart.data.datasets = [];
59 this.update();
60 }
61
62 update() {
63 this.#chart.update();
64 }
65 }