1

Im generating Chart4PHP. In sample it takes data like this

$p->data = array(array(array("2010/10",-48),array("2011/01",238),array("2011/02",395)));

I have array "rows" constructed of row[date][units]. Im storing it in this way:

$rows = array();
for(...)
{
$row[date] = $mydate;
$row[units]= $myunits;
$rows[]=$row;
}

What I should make additionally to be able to use it as $p->data = $rows;

4
  • $rows['data'][] = $row? Commented Sep 24, 2015 at 18:55
  • Are you sure you need a 3-dimensional array, not 2-dimensional? Do you have a link to the Chart4PHP documentation? Commented Sep 24, 2015 at 19:06
  • Found it at chartphp.com/docs Commented Sep 24, 2015 at 19:08
  • chartphp.com/demo Line chart sample Commented Sep 24, 2015 at 19:12

1 Answer 1

1

To add the extra array container, call array() with the rows array as the argument.

$data = array(array('date' => "2010/10", 'units' => -48),
              array('date' => "2011/01", 'units' => 238),
              array('date' => "2011/02", 'units' => 395));

foreach ($data as $d) {
    $mydate = $d['date'];
    $myunits = $d['units'];
    $rows[] = array($mydate, $myunits);
}
$p->data = array($rows);
Sign up to request clarification or add additional context in comments.

2 Comments

in this way it takes only $mydate to show in the output, it wont read second value of array. If i change $rows[] = array($myunits, $mydate); it shows units (so data is OK).
My code should create the exact result that you asked for in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.