Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 929e87d

Browse files
committed
Fixes errors in charts without scales option (like pie)
1 parent 9e066b1 commit 929e87d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/plugin/hierarchical.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,27 @@ function generateCode(labels) {
5353
const HierarchicalPlugin = {
5454
id: 'chartJsPluginHierarchical',
5555

56+
_isValidScaleType(chart, scale) {
57+
if (!chart.config.options.scales.hasOwnProperty(scale)) {
58+
return false;
59+
}
60+
if (!Array.isArray(chart.config.options.scales[scale])) {
61+
return false;
62+
}
63+
return chart.config.options.scales[scale][0].hasOwnProperty('type');
64+
},
65+
5666
/**
5767
* checks whether this plugin needs ot be enabled based on wehther one is a hierarchical axis
5868
*/
5969
_enabled(chart) {
60-
if (chart.config.options.scales.xAxes[0].type === 'hierarchical') {
70+
if (!chart.config.options.hasOwnProperty('scales')) {
71+
return null;
72+
}
73+
if (this._isValidScaleType(chart, 'xAxes') && chart.config.options.scales.xAxes[0].type === 'hierarchical') {
6174
return 'x';
6275
}
63-
if (chart.config.options.scales.yAxes[0].type === 'hierarchical') {
76+
if (this._isValidScaleType(chart, 'yAxes') && chart.config.options.scales.yAxes[0].type === 'hierarchical') {
6477
return 'y';
6578
}
6679
return null;

0 commit comments

Comments
 (0)