Need to sort the data based on Month

by npugazhendhi » Wed Apr 20, 2016 11:40 am

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.
Attachments
SnipImage (2).JPG
Need to sort the data series month wise
SnipImage (2).JPG (17.14 KiB) Viewed 1980 times
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

by Rostislav » Wed Apr 20, 2016 1:06 pm

Check my post here viewtopic.php?f=19&t=409#p1125

You will need to place the month names in their order into the array and replace 'status' with the name of the month field.
User avatar
Rostislav
 
Posts: 61
Joined: Fri Oct 09, 2015 10:51 am

by npugazhendhi » Thu Apr 21, 2016 7:12 am

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;
}
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

by npugazhendhi » Thu Apr 21, 2016 7:25 am

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 ?
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

by Rostislav » Thu Apr 21, 2016 10:55 am

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:
Code: Select all
Array.prototype.sort.call(config.series[i].data, function(a, b) {
   return ordering.indexOf(a.Month) - ordering.indexOf(b.Month);
})
User avatar
Rostislav
 
Posts: 61
Joined: Fri Oct 09, 2015 10:51 am

by npugazhendhi » Thu Apr 21, 2016 11:29 am

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.
Attachments
monthsort_notworking.png
monthsort_notworking.png (34.86 KiB) Viewed 1956 times
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

by Rostislav » Thu Apr 21, 2016 12:17 pm

This is working for me:
Code: Select all
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;
}


month needs to be the internal name of the month field
User avatar
Rostislav
 
Posts: 61
Joined: Fri Oct 09, 2015 10:51 am

by npugazhendhi » Fri Apr 22, 2016 5:55 am

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.
Attachments
Month1.JPG
Month1.JPG (77.51 KiB) Viewed 1948 times
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

by Rostislav » Fri Apr 22, 2016 10:22 am

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

Code: Select all
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;
}
User avatar
Rostislav
 
Posts: 61
Joined: Fri Oct 09, 2015 10:51 am

by npugazhendhi » Fri Apr 22, 2016 11:04 am

Hey.....Hurray..!! Thanks a lot....i got it now . Thanks for your help.
npugazhendhi
 
Posts: 19
Joined: Wed Apr 20, 2016 11:27 am

Next

Return to Dashboard Designer for SharePoint 2013

cron