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.
3
votes
@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
I mean more info about what version are you using and could you provide snippet of codes.
- Grant Zhu
@Grant Zhu : version - ext-4.0.7-gpl
- Nissanka
4 Answers
2
votes
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
}
}
}]
1
votes
0
votes
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.