Page 1 of 1

PHP/SWF Charting Software

Posted: Fri Jul 14, 2006 5:38 am
by NotOnUrNelly
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,

I am trying to generate a simple line chart using the PHP/SWF 

http://www.maani.us/charts/index.php?me ... Chart_Data

I am trying to read the values from a mysql database this is not a problem

the problem comes from trying to generate an array from the values and plot them as a graph as shown in the tutorial

My table is a simpletable structured as below

  Question  Score  
      Q1      14 
      Q2      7 
      Q5      12 
      Q3      2 
      Q4      8 

The code I am using to generate the graphs is shown below

Code: Select all

<?php

include "charts.php";
$chart ['chart_type'] = "line";

$chart ['chart_data'][0][0]="";
$chart ['chart_data'][1][0]="Q1";
$chart ['chart_data'][2][0]="Q2";
$chart ['chart_data'][3][0]="Q3";
$chart ['chart_data'][4][0]="Q4";
$chart ['chart_data'][5][0]="Q5";
mysql_connect ("localhost","x04recru_jamie","tatungjj");
mysql_select_db ("x04recru_main");

$result = mysql_query("SELECT MIN(Score) as MinScore from tblChart");
$MinScore = mysql_result ($result,0,"MinScore");


$result = mysql_query ("SELECT * FROM tblChart");

for ($i=0; $i < mysql_num_rows($result); $i++){

switch (mysql_result ($result,$i,"Question")){
case "Q1":
$row = 1;
break;

case "Q2":
$row = 2;
break;

case "Q3":
$row = 3;
break;

case "Q4":
$row = 4;
break;

case "Q5":
$row = 5;
break;
}

$col = mysql_result ($result,$i,"Score")-$MinScore + 1;


$chart ['chart_data'][0][$col]=mysql_result($result,$i,"Question");
$chart ['chart_data'][$row][$col]=mysql_result($result,$i,"Score");
}


//echo $MinScore;
SendChartData ($chart);
?>
The vlaues seem to be falling out of the array okay and plotting on the graph as shown below

http://www.recruitmentnl.info/training/chart_test.php


the trouble is I cannot configure the array correctly to move the line graph from the first column (ie far left) across to the right columns to represent the values.

Has anyone any experience of this add in and could possibly help me with this.

Many Thanks
Jamie


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]