3

I'm trying to assign a return value from a method to an array and in a second step to place this array into the addPoints() method of pChart.

Right now I'm using the following code:

$dataUsage = array();
for ($i = 1; $i < 31; $i++) {
        $dataUsage[$i - 1] = getDailyUsage($i);
}
$dataUsage[30] = getDailyUsage(31);

The getDailyUsage method looks like this:

function getPeriod() {
    return date("Y-m");
}

function getDailyUsage($day) {
        $var = getPeriod() . "-" . $day;
        global $pdo;
        $sql = "SELECT COUNT(  `id` ) FROM  `logs` WHERE timestamp = '$var'";
        $q = $pdo->prepare($sql);
        $q->execute();
        $q->setFetchMode(PDO::FETCH_ASSOC);
        $number = $q->fetchColumn(0);
        return $number;
}

To display the data into the pChart I'm running this:

$myData->addPoints($dataUsage, "Serie2");

As output I'm getting the default html icon as if I'm not finding the picture I'm looking for.

What really makes me curious is that I don't get any errors if I run this code:

$array = array();
for ($i = 1; $i < 31; $i++) {
    $array[$i - 1] = $i;
}
$array[30] = 31;

$myData->addPoints($array, "Absissa");

Since this is my first post I'm looking for tips to improve my questions, so feel free to leave a comment.

Edit: If I use:

$dataUsage = array();
for ($i = 1; $i < 31; $i++) {
        $dataUsage[$i - 1] = $i;
}
$dataUsage[30] = $i;

I can draw the image. But I couldn't even run it when I tried:

$myData->addPoints(array(getDailyUsage(1), getDailyUsage(2)), "Absissa")
2
  • I'd recommend to go through the process and echo out stuff as you go through it. This will help you find where the source of you problem is! I'd recommend looking at the function array_push if you are creating a new array and are trying to add stuff to it :) Commented May 6, 2015 at 17:59
  • The problem is that the array is technically correct, but I can't fill it with the return value of getDailyUsage()
    – Peter
    Commented May 6, 2015 at 18:08

1 Answer 1

0

I got help for my problem and want to share the solution: I had to check for the html source in the browser. The .php file which displays the picture showed the error. Problem was that the file, which contains the connection information wasn't included.

I recommend you to look at the picture / file if you're working with pChart to avoid those errors.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.