Javascript Decoded data can't be plotted out in graph

Hi,
I have written a JavaScript decode function.
I can see my data sent from LoRa node at the Device Data tab.
I can also see my data in the table form in grafana or chronograf when my data is put into influxDB. But the problem is that my data just can’t be plotted out into graph form.
I feel like something is missing in the JavaScript decode function. But I just don’t know what.

Below is my function
function Decode(fPort, bytes, variables) {
if(bytes.length == 1) {
if(bytes[0] == 1) {
return {
‘button’: ‘activated’
}
} else {
return {
‘error’: ‘button action unknown’
}
}
} else {
var pkFreq = ‘’;
var cnt;

  for (cnt = 0; cnt < bytes.length; cnt++) {      	

// exclude non-number>
if ((bytes[cnt] >= 48) && (bytes[cnt] <= 57)) {
pkFreq += String.fromCharCode(bytes[cnt]);
}
// exclude non-number<
}

     return {            
        'pkfrequency': pkFreq            
     }

}
}

First, you can’t plot “activated” unless you define that in your data visualization software. Usually, we use “1” or “true”. Its opposite (“non-activated”) state should also be detected and returned as “0” or “false”. You can detect other states (e.g., undefined) but, again, don’t return “button action unknown” but “NaN” or something more standardized.

Second, I presume you’re pulling the time-stamp of transmission out at some point? Not all sensors send such data, but some do - you’ll need to check your technical data. It’s normally safe to assume time received == time of event, but in a congested/very busy area, maybe not. Thus, you should keep track Fcnt at least, to have a feel for what’s going on.

Also, please learn to select your JS code and tag it as “preformatted text”
preformatted
so it doesn’t get mangled:

function Decode(fPort, bytes, variables) {
if (bytes.length == 1) {
    if (bytes[0] == 1) {
        return {
            "button": "activated"
        }
    } else {
        return {
            "error": "button action unknown"
        }
    }
} else {
    var pkFreq = "";
    var cnt;

    for (cnt = 0; cnt < bytes.length; cnt++) {
        // exclude non-number>
        if ((bytes[cnt] >= 48) && (bytes[cnt] <= 57)) {
            pkFreq += String.fromCharCode(bytes[cnt]);
        }
        // exclude non-number<
    }

    return {
        "pkfrequency": pkFreq
    }
}

Hi fmgst,
Thanks for your reply.

I found the cause of why graph can’t be plotted.

It is because my variable pkFreq has to be in number. Currently it is in string form. That’s why it can’t be plotted.

I have to convert it to number like this
‘pkfrequency’: parseInt(pkFreq)

Then it can be plotted out.

Thanks so much for your guidance.

Regards,