Skip to content

Commit 4a7293a

Browse files
author
Jelte Lagendijk
committed
Fix #72 again, making sure it starts at zero even without data points
1 parent 8c94dd2 commit 4a7293a

File tree

7 files changed

+39
-20
lines changed

7 files changed

+39
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ChartJS",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"description": "This widget is a wrapper for the ChartJS library and you can use it to visualize your aggregated data.",
55
"license": "Apache License, Version 2",
66
"author": "Mendix",

src/ChartJS/widgets/BarChart/widget/BarChart.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ define([
105105
this._chart.update(1000);
106106
this._chart.bindEvents(); // tooltips otherwise won't work
107107
} else {
108-
this._chart = new this._chartJS(this._ctx, {
108+
var chartOptions = {
109109
type: "bar",
110110
data: data,
111111
options: {
@@ -195,7 +195,14 @@ define([
195195
// Custom tooltip?
196196
customTooltips : false,
197197
}
198-
});
198+
};
199+
200+
if (this.scaleBeginAtZero) {
201+
chartOptions.options.scales.yAxes[0].ticks.suggestedMin = 0;
202+
chartOptions.options.scales.yAxes[0].ticks.suggestedMax = 4;
203+
}
204+
205+
this._chart = new this._chartJS(this._ctx, chartOptions);
199206

200207
this.connect(window, "resize", lang.hitch(this, function () {
201208
this._resize();

src/ChartJS/widgets/Core.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ define([
7171
// Activate chartJS.
7272
this._chartJS = _charts.noConflict();
7373

74-
console.log(this._chartJS);
75-
7674
// Fonts
7775
this._font = this.labelFont || "Helvetica Neue";
7876

src/ChartJS/widgets/LineChart/widget/LineChart.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ define([
120120
this._chart.update(1000);
121121
this._chart.bindEvents(); // tooltips otherwise won't work
122122
} else {
123-
logger.debug("stacked:" + this.isStacked);
123+
//logger.debug("stacked:" + this.isStacked);
124124

125-
this._chart = new this._chartJS(this._ctx, {
125+
var chartOptions = {
126126
type: "line",
127127
data: data,
128128
options: {
@@ -231,7 +231,14 @@ define([
231231
customTooltips : false, //lang.hitch(this, this.customTooltip)
232232

233233
}
234-
});
234+
};
235+
236+
if (this.scaleBeginAtZero) {
237+
chartOptions.options.scales.yAxes[0].ticks.suggestedMin = 0;
238+
chartOptions.options.scales.yAxes[0].ticks.suggestedMax = 4;
239+
}
240+
241+
this._chart = new this._chartJS(this._ctx, chartOptions);
235242

236243
this.connect(window, "resize", lang.hitch(this, function () {
237244
this._resize();
@@ -243,7 +250,6 @@ define([
243250
if (this.onclickmf) {
244251
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
245252
}
246-
247253
}
248254
}
249255

src/ChartJS/widgets/StackedBarChart/widget/StackedBarChart.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ define([
107107
this._chart.bindEvents(); // tooltips otherwise won't work
108108
} else {
109109

110-
this._chart = new this._chartJS(this._ctx, {
110+
var chartOptions = {
111111
type: "bar",
112112
data: data,
113113
options: {
@@ -199,19 +199,27 @@ define([
199199
// Custom tooltip?
200200
customTooltips : false, //lang.hitch(this, this.customTooltip)
201201
}
202-
});
203-
}
202+
};
203+
204+
if (this.scaleBeginAtZero) {
205+
chartOptions.options.scales.yAxes[0].ticks.suggestedMin = 0;
206+
chartOptions.options.scales.yAxes[0].ticks.suggestedMax = 4;
207+
}
208+
209+
this._chart = new this._chartJS(this._ctx, chartOptions);
204210

205-
this.connect(window, "resize", lang.hitch(this, function () {
206-
this._resize();
207-
}));
211+
this.connect(window, "resize", lang.hitch(this, function () {
212+
this._resize();
213+
}));
208214

209-
// Add class to determain chart type
210-
this._addChartClass("chartjs-stacked-bar-chart");
215+
// Add class to determain chart type
216+
this._addChartClass("chartjs-stacked-bar-chart");
211217

212-
if (this.onclickmf) {
213-
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
218+
if (this.onclickmf) {
219+
on(this._chart.chart.canvas, "click", lang.hitch(this, this._onClickChart));
220+
}
214221
}
222+
215223
}
216224
});
217225
});

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="ChartJS" version="3.4.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="ChartJS" version="3.4.1" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="ChartJS/widgets/BarChart/BarChart.xml"/>
66
<widgetFile path="ChartJS/widgets/LineChart/LineChart.xml"/>

test/widgets/ChartJS.mpk

240 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)