Can someone know how to format extjs chart axis to integer. Numeric axis gives decimal values too. I want only the integer values in axis.
Asked
Active
Viewed 4,291 times
3
-
@Grant Zhu : I want to draw line chart time against visits. Visits cannot be decimal(0.2... like). But when i used visit axis type as numeric lables of the axis show with decimels(1.2, 3.6... like). – Nissanka Feb 22 '12 at 05:39
-
I mean more info about what version are you using and could you provide snippet of codes. – Grant Zhu Feb 22 '12 at 05:51
-
@Grant Zhu : version - ext-4.0.7-gpl – Nissanka Feb 22 '12 at 11:02
4 Answers
2
define your minimum and maximum, then add majorTickSteps with your biggest axis value on your data array minus one, so it is one less than your maxium
credit to @bittercoder on majorTickSteps comment on Sencha ExtJs 4.1.3
axes: [{
type: 'Numeric',
position: 'left',
fields: ['data1', 'data2', 'data3'],
title: 'Number of Hits',
grid: {
odd: {
opacity: 1,
fill: '#ddd',
stroke: '#bbb',
'stroke-width': 1
}
},
minimum: 0,
maximum: 10,
majorTickSteps: 9 // one less than max
}, {
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Month of the Year',
grid: true,
label: {
rotate: {
degrees: 315
}
}
}]

yesk13
- 89
- 1
- 5
1
In your Model, set the field types to 'int' and it will discard decimals.
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'Foo',
type: 'int'
},
{
name: 'Bar',
type: 'int'
}
]
});

Brett
- 2,706
- 7
- 33
- 49
-
1This does not work for ExtJS 4.1, the axis still renders with decimal values. – egerardus Jun 30 '12 at 20:54
0
You can use the label renderer function when you define the axis to do this
axes: [{
type: 'Numeric',
position: 'left',
grid: true,
fields: ['data1', 'data2'],
label: {
renderer: function (v) {
return v.toFixed(0);
}
}
},
{ ... }
]
You can do anything you want with the axis values when you have v (v is the value of the label). In the case above .toFixed(0) rounds to the nearest integer.

wilsjd
- 2,178
- 2
- 23
- 37
0
I was facing similar issue.
yAxis: new Ext.chart.NumericAxis({
displayName: 'Visits',
labelRenderer: function(v) {
// return a value only if it is an integer
if(v.toString().indexOf(".") === -1){
return v;
}
}
})
This worked for me

BhandariS
- 606
- 8
- 20