PDA

View Full Version : Chart maximum and/or constrained axis on stacked area graph



craigsimons
23 May 2013, 2:01 PM
Problem: I have a stacked area series that, if summed, should not exceed 100%. Therefore, it would make sense to set the axis maximum value to 100. Unfortunately, as per the docs (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.chart.axis.Numeric-cfg-constrain), the minimum, maximum and constrained properties are "...ignored for stacked charts".

In my particular case, I do not want the axis to be auto-scaled (I don't want a stacked 9% to look the same as %99%).

So, how might I achieve this? and afterrender listener to set scale manually?

slemmon
28 May 2013, 10:26 AM
I'm afraid there's not a mechanism to adjust the maximum of the y axis on the stacked area charts. I've seen where some users have created an extra record in the store with styling of transparent to augment the data so that it meets a certain maximum. That falls apart a little when you have a legend associated with the chart since the space-holder record will be represented in the legend, but works if no legend is displayed.

craigsimons
28 May 2013, 11:03 AM
The workaround I ended up using was just to create a new axis type without any special treatment of stacked series. In my case it works out well, but I realize that it's probably there for a reason.


Ext.define('Ext.chart.axis.ConstrainedStackedNumeric', {
extend: 'Ext.chart.axis.Numeric',
alternateClassName: 'Ext.chart.ConstrainedStackedNumericAxis',
type: 'ConstrainedStackedNumeric',
alias: 'axis.constrainedstackednumeric',


constructor:function(cnfg){
this.callParent(arguments);//Calling the parent class constructor
this.initConfig(cnfg);//Initializing the component
},


processView: function() {
var me = this,
chart = me.chart,
series = chart.series.items,
i, l;


if (me.constrain) {
me.doConstrain();
}
}
});

slemmon
28 May 2013, 2:37 PM
No harm in making your own extensions to accomplish what you're looking to do. Just keep in mind that if you're doing something contrary to the design of the framework you may be saddled with the need to updated your extensions with future framework versions as they come out - I know - I've done the same thing multiple times. I'll make a plugin or an extension knowing that future changes could hobble my extension and... they do. Keeps you on your toes. :)