This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

chartist to display nice pie...
#28
I need help.
Not so good with Javascript... Sleepy 


I have this code:

Code:
function getdate(offset) {
  var date = new Date();

  date.setDate(date.getDate() + offset+1);

  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();

  return { year, month, day };
}






function getdata(nom, dayBefore, dayBase,total) {
    var result = [];
  var trendsName = [];
  var trendsAddress = [];
    var myJsonString='';

  //FIND GA NAME AND ADDRESS
  $.each(grp.tag(nom), function(id, object) {
    trendsName.push(object.name);
    trendsAddress.push(Scada.encodeGroupAddress(object.address));
  });

  // CREATE ARGUMENT
  var data = JSON.stringify({
    trends: trendsAddress,
    dates: {
      start: getdate(dayBefore),
      end: getdate(dayBase),
    },
    // resolution: 86400,
    // timestamps: true,
  });

  // TRENDS.LP POST
  $.post('/user/trends.lp', data, function(resp) {

    $.each(resp, function(id, object) {

      // SUM TO TOTAL
      if (total>0) {
        let totVal = 0;
        for (let l = 0; l < object.length; l++) {
           totVal += object[l];
        }
          result.push(trendsName[id],totVal);

      // NO TOTAL
      } else {
        result.push(trendsName[id],object);
      }
    });
 
  });
   
  return result;

}


My problem I can't iterate on the array on the function:

for example with


//last day
let day=getdata(classImage,-1,0,1);

this don't work. Lentgth return 0...

for (let i = 0; i < day .length; i++) {
console.log(day[i])
}

however a console.log of day show all result... Rolleyes  and a length. I gess there is something with scope/timelaps but I try also in jquery, with map... all same.

Code:
Array []

0: "PV - Active Energy No reset"

1: 16854

2: "General- Active Energy No reset"

3: 19329

length: 4

<prototype>: Array []


If our so nice admin could help me a bit, greatly appreciated.
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply


Messages In This Thread
chartist to display nice pie... - by domotiqa - 05.01.2022, 08:56
RE: chartist to display nice pie... - by jmir - 14.02.2022, 11:32
RE: chartist to display nice pie... - by jmir - 14.02.2022, 13:34
RE: chartist to display nice pie... - by jmir - 15.02.2022, 11:15
RE: chartist to display nice pie... - by Acla - 12.06.2023, 05:05
RE: chartist to display nice pie... - by JRP - 08.09.2022, 16:18
RE: chartist to display nice pie... - by Acla - 12.06.2023, 15:44
RE: chartist to display nice pie... - by jmir - 25.03.2024, 14:49
RE: chartist to display nice pie... - by domotiqa - 08.04.2024, 13:16

Forum Jump: