Skip to content

Commit 445be96

Browse files
committed
Added the option to set labels on the Axes
You can now add a label on both the X-axis as the Y-axis. Added two properties in XMLs for all relevant charttypes. When a string is given, that value will be used as a label. Leave empty for no label.
1 parent 7fe3063 commit 445be96

File tree

8 files changed

+60
-0
lines changed

8 files changed

+60
-0
lines changed

src/ChartJS/widgets/BarChart/BarChart.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
<category>Appearance</category>
1313
<description>Initial width of the chart canvas, will be ignored when responsive property is set to 'Yes'</description>
1414
</property>
15+
<property key="xLabel" type="string" required="false" defaultValue="">
16+
<caption>X-axis label</caption>
17+
<category>Appearance</category>
18+
<description>Label to show on the X-axis. Leave empty for no label</description>
19+
</property>
20+
<property key="yLabel" type="string" required="false" defaultValue="">
21+
<caption>Y-axis label</caption>
22+
<category>Appearance</category>
23+
<description>Label to show on the Y-axis. Leave empty for no label</description>
24+
</property>
1525
<property key="height" type="integer" required="true" defaultValue="250">
1626
<caption>Height</caption>
1727
<category>Appearance</category>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ define([
110110
options: {
111111
scales : {
112112
xAxes: [{
113+
scaleLabel: {
114+
display: (this.xLabel !== "") ? true : false,
115+
labelString: (this.xLabel !== "") ? this.xLabel : "",
116+
fontFamily: this._font
117+
},
113118
ticks : { fontFamily: this._font, }
114119
}],
115120
yAxes: [{
121+
scaleLabel: {
122+
display: (this.yLabel !== "") ? true : false,
123+
labelString: (this.yLabel !== "") ? this.yLabel : "",
124+
fontFamily: this._font
125+
},
116126
ticks : { fontFamily: this._font, }
117127
}],
118128

src/ChartJS/widgets/LineChart/LineChart.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
<category>Appearance</category>
1515
<description>Initial width of the chart canvas, will be ignored when responsive property is set to 'Yes'</description>
1616
</property>
17+
<property key="xLabel" type="string" required="false" defaultValue="">
18+
<caption>X-axis label</caption>
19+
<category>Appearance</category>
20+
<description>Label to show on the X-axis. Leave empty for no label</description>
21+
</property>
22+
<property key="yLabel" type="string" required="false" defaultValue="">
23+
<caption>Y-axis label</caption>
24+
<category>Appearance</category>
25+
<description>Label to show on the Y-axis. Leave empty for no label</description>
26+
</property>
1727
<property key="isStacked" type="boolean" required="true" defaultValue="false">
1828
<caption>Stacked</caption>
1929
<category>Appearance</category>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ define([
127127
yAxes: [{
128128
//If stacked is set to true, the Y-axis needs to be stacked for it to work
129129
stacked: this.isStacked,
130+
scaleLabel: {
131+
display: (this.yLabel !== "") ? true : false,
132+
labelString: (this.yLabel !== "") ? this.yLabel : "",
133+
fontFamily: this._font
134+
},
130135
ticks : { fontFamily: this._font }
131136
}],
132137
xAxes: [{
138+
scaleLabel: {
139+
display: (this.xLabel !== "") ? true : false,
140+
labelString: (this.xLabel !== "") ? this.xLabel : "",
141+
fontFamily: this._font
142+
},
133143
ticks : { fontFamily: this._font, }
134144
}]
135145
},

src/ChartJS/widgets/StackedBarChart/StackedBarChart.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
<category>Appearance</category>
1818
<description>Initial height of the chart canvas, will be ignored when responsive property is set to 'Yes'</description>
1919
</property>
20+
<property key="xLabel" type="string" required="false" defaultValue="">
21+
<caption>X-axis label</caption>
22+
<category>Appearance</category>
23+
<description>Label to show on the X-axis. Leave empty for no label</description>
24+
</property>
25+
<property key="yLabel" type="string" required="false" defaultValue="">
26+
<caption>Y-axis label</caption>
27+
<category>Appearance</category>
28+
<description>Label to show on the Y-axis. Leave empty for no label</description>
29+
</property>
2030
<property key="labelFont" type="string" required="true" defaultValue="Helvetica Neue">
2131
<caption>Font</caption>
2232
<category>Appearance</category>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,23 @@ define([
113113
scales: {
114114
xAxes: [{
115115
stacked: true,
116+
scaleLabel: {
117+
display: (this.xLabel !== "") ? true : false,
118+
labelString: (this.xLabel !== "") ? this.xLabel : "",
119+
fontFamily: this._font
120+
},
116121
ticks: {
117122
fontFamily :this._font
118123
//beginAtZero: true
119124
}
120125
}],
121126
yAxes: [{
122127
stacked: true,
128+
scaleLabel: {
129+
display: (this.yLabel !== "") ? true : false,
130+
labelString: (this.yLabel !== "") ? this.yLabel : "",
131+
fontFamily: this._font
132+
},
123133
ticks: {
124134
fontFamily: this._font
125135
//suggestedMax: 10

test/[Test] ChartJS.mpr

20 KB
Binary file not shown.

test/widgets/ChartJS.mpk

507 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)