Hi all,
I've search long and hard for an answer to this but I haven't been able to implement anything correctly.
I'm trying to build a php JpGraph script and asking in the forums there only got me so far. What I am trying to do is create a two dimensional array ($datay) with the pitch_type as the first dimension, date the second dimension, and Vertical_Movement as my data to go on the y-axis graphing
Each pitch type would be a separate line on the graph, hence why I was told I need a two-dimensional array.
If anyone could take a look at my code and tell me how to create the two-dimensional array from my query, I'd greatly appreciate it.
include 'config.php';
include 'opendb.php';
require_once('jpgraph.php');
require_once('jpgraph_line.php');
require_once('jpgraph_bar.php');
// gets variables from form
$first = Trim($_POST["first"]);
$last = Trim($_POST["last"]);
$year = $_POST["year"];
$month = $_POST["month"];
$day = $_POST["day"];
$year1 = $_POST["year1"];
$month1 = $_POST["month1"];
$day1 = $_POST["day1"];
$date = $date = $year ."-". $month ."-". $day;
$date1 = $year1 ."-". $month1 ."-". $day1;
// sql query
$sql = "SELECT games.date, pitches.pitch_type,
AVG( pitches.z0 ) AS 'Vertical_Release_Point',
AVG( pitches.start_speed ) AS 'Start_Speed',
AVG( pitches.end_speed ) AS 'End_Speed',
AVG( pitches.x0 ) AS 'Horizontal_Release_Point',
AVG( pitches.pfx_x ) AS 'Horizontal_Movement',
AVG( pitches.pfx_z ) AS 'Vertical_Movement'
FROM pitches
LEFT JOIN (
players
LEFT JOIN (
atbats
LEFT JOIN games ON atbats.game_id = games.game_id
) ON players.eliasID = atbats.pitcher
) ON pitches.ab_id = atbats.ab_id
WHERE players.last = '$last' AND players.first = '$first'
AND pitches.pitch_type IS NOT NULL
AND games.date between '$date' and '$date1'
GROUP BY games.date, pitches.pitch_type
ORDER BY games.date, pitches.pitch_type";
$result = mysql_query($sql) or die("Query error: ". mysql_error());
$row = mysql_fetch_assoc($result);
$totalrows_result = mysql_num_rows($result);
//what I need to do is have the pitches be the first dimension
//and I should have the games.date be the 2nd dimension
//and my datay would be the Vertical Movement plot
//datay represents fastball
//$datay2 = curveball
//datay3 = changeup
//datay4 = slider
//datay5 = sinker
//datay6 = splitter
//datay7 = fast_change
$datay=array();
$labelx=array();
$ydata=array(); ///just an empty array to bring the lines into the graph rather than start directly on y-axis
do {
array_push($datay, $row_result['Vertical_Movement']);
array_push($ydata, '');
array_push($labelx, $row_result['date']);
} while ($row_result = mysql_fetch_assoc($result));
// set general graph details
// the cache/refresh problem is solved here
$graph = new Graph(600,400);
$graph->img->SetMargin(50,50,50,60);
$graph-> SetScale( "textlin");
// set graph titles
$graph->title->SetFont(FF_FONT2, FS_BOLD, 14);
$graph->title->Set("Efficiency");
$graph->ygrid->Show();
$graph->xgrid->Show();
// set the y-axis and title it
$graph->yaxis->title->Set("Percentage");
$graph->yaxis->SetLabelAngle(0);
$graph->yaxis->scale->SetGrace(10,5);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL,12);
// set the x-axis and title it
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10);
$graph->xaxis->SetTickLabels($games);
$graph->xaxis->scale->SetGrace(10,10);
$graph->SetTickDensity(TICKD_DENSE);
$graph->xaxis->SetLabelMargin(1);
//Add a lineplot to stroke the smooth curve we got
//from the original control points
$lineplot = new LinePlot($datay);
$lineplot->SetColor ('orange');
$graph->Add($lineplot);
//define legend
$lineplot->SetLegend("Vert");
// Adjust the legend position
$graph->legend->SetAbsPos(10,10,'right','top');
$graph->Stroke();
include 'closedb.php';
Again, any help would be much appreciated because this is one of the final steps I need in order to get my webpage live. Thanks in advance for the help.