Extract the array in json components, which look like consecutive arrays

1

I am faced with the following dilemma:

I am using the api C3.js of statistics in a project, where I want to make a graph of time of day and the accesses to a building, I have:

var chart4 = c3.generate({

    bindto: '#estadisticaTemporal',
    data: {
        x: 'Hora',
        xFormat: '%Y-%m-%d %H:00:00',
        columns:
            {!! $fechaAcceso['horas'] !!},
            {!! $fechaAcceso['acceso'] !!}
    },
    axis: {
        x: {
            type: 'timeseries',
            // if true, treat x value as localtime (Default)
            // if false, convert to UTC internally
            localtime: false,
            tick: {
                format: '%Y-%m-%d %H:00:00'
            }
        }
    }
});

The array is formed by:

[
  "horas" => ["Hora" , "2017-09-06 10:00:00"]
  "acceso" => [["entradas" , "0"],["salidas,"1"]]
]

The question that prints them to me this way:

columns:
             ["Hora" , "2017-09-06 10:00:00"],
           [["entradas" , "0"],["salidas,"1"]]
    },

What I want is:

columns:
             ["Hora" , "2017-09-06 10:00:00"],
           ["entradas" , "0"],["salidas","1"] // Como podéis ver es distinto
    },
    
asked by CodeNoob 06.09.2017 в 12:03
source

1 answer

1

Just what I did after turning it around, was to understand that it was a json, at the end of the day it is as if it were a string for the PHP variable, therefore I played with strlen to tell me the length and with substr to improve cut where I was interested.

$array = [
  ["entradas" , 0,2,3,2,31,32,32,23,2,1,4,1,5,1,2,3,4],
  ["salidas" , 1,2,3,44,2,5,6,1,2,3,4,5,6,1,2,3,4],
];
$arrayJson = json_encode($array);
echo json_encode($array);
$arrayFormat = substr($arrayJson,1,strlen($arrayJson));
$arrayFormat = substr($arrayFormat,-strlen($arrayJson),-1);
echo $arrayFormat;

Departures:

 // primer echo (aqui lo pongo formateado
 [
  ["entradas",0,2,3,2,31,32,32,23,2,1,4,1,5,1,2,3,4],
  ["salidas",1,2,3,44,2,5,6,1,2,3,4,5,6,1,2,3,4]
 ]
 // Segundo echo
 ["entradas",0,2,3,2,31,32,32,23,2,1,4,1,5,1,2,3,4],
 ["salidas",1,2,3,44,2,5,6,1,2,3,4,5,6,1,2,3,4]

As a result I would give this:

As you can see where you put the dates, are the axis of the X and the other two the two graphics superimposed the Y.

As clarification:

    
answered by 06.09.2017 в 21:41