Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //On the comsuption site (/Meter/Consumption) you should be able to paste in this
- //script in the chrome-console and the four largest values should be flagged.
- (function () {
- //Helper function for finding largest values in array
- var findLargestValues = function (arr, howManyToFind) {
- if (!arr || arr.length === 0) {
- return [];
- }
- howManyToFind = arr.length < howManyToFind ? arr.length : howManyToFind;
- var clone = arr.slice(); //clone to not temper with the original
- var largest = []; //{index,value}
- for (var i = 0; i < howManyToFind; i++) {
- var max = Math.max.apply(null, clone); // get the max value
- if (max) {
- var maxi = clone.indexOf(max); //get the max index
- clone[maxi] = -Infinity; // replace max in the array with -infinity (for performance)
- largest.push({
- index: maxi,
- value: max
- });
- }
- }
- return largest;
- }
- var $chart = $('#chart-container');
- var chart = $chart.highcharts();
- var hourValues = eval($chart.attr('data-serie-data'));
- var firstDate = eval($chart.attr('data-serie-pointstart'));
- var largestFour = findLargestValues(hourValues, 4);
- var flagData = largestFour.sort(function (a, b) {
- return a.index - b.index;
- }).map(function (element) {
- return {
- x: firstDate + element.index * 60 * 60 * 1000,
- title: element.value
- }
- });
- var data = {
- type: 'flags',
- name: 'Flags on series',
- data: flagData,
- onSeries: 'thisyear', //Draw on consumption graph
- shape: 'flag',
- }
- chart.addSeries(data);
- } ());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement