notonurnelly Posted July 13, 2006 Share Posted July 13, 2006 Hi all,I am trying to generate a simple line chart using the PHP/SWF http://www.maani.us/charts/index.php?menu=Tutorial&submenu=Chart_DataI am trying to read the values from a mysql database this is not a problemthe problem comes from trying to generate an array from the values and plot them as a graph as shown in the tutorialMy 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<?phpinclude "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 belowhttp://www.recruitmentnl.info/training/chart_test.phpthe 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 ThanksJamie Quote Link to comment https://forums.phpfreaks.com/topic/14498-php-line-charts-phpswf-add-in/ Share on other sites More sharing options...
notonurnelly Posted July 13, 2006 Author Share Posted July 13, 2006 Bye the way the username and password for the page isjamiejamie Quote Link to comment https://forums.phpfreaks.com/topic/14498-php-line-charts-phpswf-add-in/#findComment-57397 Share on other sites More sharing options...
Barand Posted July 13, 2006 Share Posted July 13, 2006 I think you need something like this[code]<?php$res = mysql_query("SELECT question, score FROM tblChart ORDER BY question");$chart['chartdata'][0] = array('', '');while (list($q, $s) = mysql_fetch_row($res)) { $chart['chartdata'][] = array($q, $s);}?>[/code]As an aside, a line graph is good for showing changes over time, but for comparisons like this a bar chart is a better choice. EG[pre] 15 | | +++ | +++ | +++ +++ | +++ +++ 10 | +++ +++ | +++ +++ | +++ +++ +++ | +++ +++ +++ +++ | +++ +++ +++ +++ 5 | +++ +++ +++ +++ | +++ +++ +++ +++ | +++ +++ +++ +++ | +++ +++ +++ +++ +++ | +++ +++ +++ +++ +++ ------------------------------ Q1 Q2 Q3 Q4 Q5[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/14498-php-line-charts-phpswf-add-in/#findComment-57517 Share on other sites More sharing options...
notonurnelly Posted July 14, 2006 Author Share Posted July 14, 2006 Hi Thanks for your last reply,that did not seems to work for some reasonthe chart displayed just seeme dto be the standard line graph.http://www.recruitmentnl.info/training/chart_test.phpI have removed all password now.The code i am using now is<?phpinclude "charts.php";$chart ['chart_type'] = "line";mysql_connect ("localhost","x04recru_jamie","tatungjj");mysql_select_db ("x04recru_main");$res = mysql_query("SELECT Question, Score FROM tblChart ORDER BY Question");$chart['chartdata'][0] = array('', '');while (list($q, $s) = mysql_fetch_row($res)) { $chart['chartdata'][] = array($q, $s);}SendChartData ($chart);Hope someone can helpIm not sure whats going on here really, Im just following the tutorial on the PHP/SWF web site. are there any other charting options available to me?many ThanksJamie Quote Link to comment https://forums.phpfreaks.com/topic/14498-php-line-charts-phpswf-add-in/#findComment-57794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.