Need to sort the data based on Month

i need to sort the month in and display it in order monthwise like january, Febrary, March…and so on. Also i sorted the list items in the list as per the Month number in ascending (i have MonthNum field showing the month in number) but it still not displaying the chart with Months in order.
Attached the screenshot.

Check my post here Sorting order of fields

You will need to place the month names in their order into the array and replace ‘status’ with the name of the month field.

hi

thanks for the reply.

But I did change code change already as shown below.

But it seems that the sort function is not available. it says sort function not available.
from where did this sort function is being referred ?

var ordering = [‘January’, ‘February’, ‘March’, ‘May’];

for (var i = 0; i < config.series.length; i++) {
config.series[i].data.sort(function(a, b) {
return ordering.indexOf(a.Month) - ordering.indexOf(b.Month);
});
};

return true;
}

hi
thanks for the reply.
I have already changed the code as you mentioned by replacing the array items with Month but it says
sort function is not available/not found.
I Just wanted to know from where this sort function is being referred ?

Hm, that’s strange. Seems that data isn’t an array - are you doing anything in Data Source -> Advanced? The function is a standard Array function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort. You can try the following, it’ll work if data is array-like:

Array.prototype.sort.call(config.series[i].data, function(a, b) { return ordering.indexOf(a.Month) - ordering.indexOf(b.Month); })

Hi

I used your code
Array.prototype.sort.call(config.series[i].data, function(a, b) {
return ordering.indexOf(a.Month) - ordering.indexOf(b.Month);
})

But I am sorry ..it is still not working.. Month not arranged as per the Ordering array.

see the attached code and screenshot.


This is working for me:

[code]
var handlers = {};
handlers.preRender = function(config, logger) {
logger.debug('Configuration: ', config);
var ordering = [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’];
for (var i = 0; i < config.series.length; i++) {
Array.prototype.sort.call(config.series[i].data, function(a, b) {
return ordering.indexOf(a.month) - ordering.indexOf(b.month);
});
}

return true;
}[/code]

month needs to be the internal name of the month field

1 Like

Thanks for the reply.

Now the month is getting sorted but they are sorted alphabetically.

it is not sorting out based on the 'ordering' array.

Screenshot is attached.


That’s because you’ve changed chart configuration. Try this

[code]var handlers = {};
handlers.preRender = function(config, logger) {
logger.debug('Configuration: ', config);
window.config = config;
var ordering = [‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’];

Array.prototype.sort.call(config.series, function(a, b) {
return ordering.indexOf(a.data[0].month) - ordering.indexOf(b.data[0].month);
});

return true;
}[/code]

1 Like

Hey…Hurray…!! Thanks a lot…i got it now . Thanks for your help.

Hi

thanks a lot for your help.

i have another query.

Is it possible to add our own text in the Legend ( i didnt select Legend option in the style) but i want to have my Own customised text as Legend.

is that possible ?

Pugal

Please use separate threads to ask unrelated questions.
Turn legends on in the Style tab, leave the box empty. Then use the following code:

//name the first series as Series 1
config.series[0].name = 'Series 1';