Hey All,

I have a php asssociative array which stores some data in the following format:

[stew] => Array
        (
            [1] => Array
                (
                    [2] => 100
                )

        [2] => Array
            (
                [2] => 50
                [4] => 50
            )

        [3] => Array
            (
                [2] => 66.666666666667
                [4] => 33.333333333333
            )

        [4] => Array
            (
                [2] => 50
                [3] => 25
                [4] => 25
            )


    )

)

The first number represents the game number, the next is the number of goals scored, and the final figure represents the % of games where that number of goals scored. I'm wanting to graph this in Jpgraph.

All the other graphs I've used I've provided standard arrays:

$datay1 = $_SESSION['stew_goals_pg'];

Array
(
    [0] => 1.35
    [1] => 1.48
    [2] => 1.5
    [3] => 1.57
)

I guess my question is this, can jpgraph use associate arrays directly or would I need to simplify the array structure a bit, and feed it this?

I'm wanting to graph those percentage figures.

Cheers

    That would of course depend upon the interface jpgraph provides. Note, however, that if you iterate over each of the subarrays in your first example above, each array is no different than the second example you gave (which you're apparently already able to use).

      I was hoping someone had specific experience with jpgraph and could answer the question regarding associative arrays, I ended up doing what you suggested in the mean time. There might be a better way but this works:

      for ($i=0; $i<$show_these; $i++) {
              for ($p=0; $p<5; $p++) {
                      if(isset($percent_spread['stew'][$i][$p])) {
                              $this1 = $percent_spread['stew'][$i][$p];
                              array_push(${'stew_'.$p.'_goal'}, $this1);
                      }
                      else {
                              array_push(${'stew_'.$p.'_goal'}, 0);
                      }
              }
      }

      Where $show_these is the number of games (which is known)

        Write a Reply...