I'm using the Flot Chart plugin to construct a bar chart. When the script receives new data, I need it to increase that value by one.
var data = [["A", 0], ["B", 0], ["C", 0], ["D", 0], ["E", 0]]
$.plot("#placeholder", [data], options);
channel.on("data", function (receiveddata) {
data[receiveddata] = data[receiveddata] + 1
$.plot("#placeholder", [data], options);
});
Now say the the channel receives "A" as the data, I want to increase by one and so on. My code shows what i've tried and also
data.recieveddata
but nothing is working.
You'd do that with :
data[0][1]++;
the array would now be :
[ ["A", 1], ["B", 0], ["C", 0], ["D", 0], ["E", 0] ]
//^ ^
//| | 1 in second array
//0 in first array
FIDDLE
To use A as a key, you need an object:
var data = {A:0, B:0, C:0};
data[receiveddata] = 2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With