Javascript, Flotr2 what does it mean [[ value,value]]

230 Views Asked by At

I'm not a javascript expert but i know how to use it. But i don't understand this code:

d2 = [[0, 3]]

What does it mean? I can't find it on google. I'm lost, i tried to change 0 by any other number but it changed nothing.

This code is part of the pie chart example on the flotr2 website: http://humblesoftware.com/flotr2/index#!basic-pie

2

There are 2 best solutions below

1
Roger On BEST ANSWER

Its an array containing one single item in it which happens to be an array that contains two elements: 0 and 3. You can extend it to be a matrix.

d2 = [
        ["1,1", "1,2", "1,3"]
      , ["2,1", "2,2", "2,3"]
      , ["3,1", "3,2", "3,3"]
];

d2[0][0] === "1,1"; // The first element

Or maybe an array of x-y points.

d2 = [[1,1], [2,2], [3,3]]; // points in the equation: y = x;
d3 = [[1,1], [2,4], [3,9]]; // points in the equation: y = x^2;

This is called an array literal. An array can contain anything, including arrays, objects etc.

enter image description here

Image taken from json.org

0
Dave On

From what I can tell

d2 = [[0, 3]]

For the above snippet:

d2: data series 2 value 0: represents the x coordinate value (ignored in pie charts) 3: represents the y coordinate value

Since the x coordinate value is ignored, why do we need it? No idea.. probably just lazy coding.

FYI: Note that:

d2 = [[, 3]]

...renders properly too, but

d2 = [[3]]

...throws an error