Ordering Chart with

Hello,

I'm working on a chart and i can't ordered categories.
It's alphabeticalalphabetical order but i want a special order.
I tried all your tutos but it's not working for me.
I would like this order :
var ordering = ['Juillet', 'Aout', 'Septembre',
'Octobre', 'Novembre', 'Décembre', 'Janvier', 'Février', 'Mars',
'Avril', 'Mai', 'Juin'];
You can see the picture below

Hello @marius,

Welcome to Plumsail Community!

You can sort data by Category using the code. Add it to Dashboard -> Advanced tab. You might need to update the code depending on your data and chart settings.

var handlers = {};
handlers.preRender = function(config, logger) {
logger.debug('Configuration: ', config);

//this will be your ordering, left to right (or top to bottom).
var ordering = ['Option2', 'Option1', 'Option3'];

for (var i = 0; i < config.series.length; i++) {
config.series[i].data.sort(function(a, b) {
//here you will need to replace Title with the exact internal name of the field that is selected as Category 
return ordering.indexOf(a.Title) - ordering.indexOf(b.Title);
});
};

return true;
}
1 Like

Thanks for your help, it's working :wink:

1 Like