Search code examples
javascriptflotr

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


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


Solution

  • 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