Jump to content


Pie chart or bar graph

  • Please log in to reply
4 replies to this topic

#1 realjumper

  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 13 July 2006 - 09:40 PM


In my application to test the users knowledge of Kanji, I ask 20 random questions. At the completion of the test I show them, amoung other things, how many they got correct, how many they got wrong, and the percentage of correct answers....the code is below. What I would like to do is to show this data in the form of a pie chart or perhaps a bar graph as it is a bit more applealing than just the stats. I'm not asking for the code, I'm just asking to be sent in the right direction so that I can find out how to do this and have a go myself. If you can set me on my way, I'd be most gratefull, thanks

$yes = $row[test_correct];
$no = $row[test_wrong];

$total = $yes+$no;

$sum = $yes/$total*'100';

$perc = round($sum); 

if ($row[test_attempts] == '20')
  echo "Test Complete";
  echo "<p>";
  echo "Correct Answers: $row[test_correct]";
  echo "<p>";
  echo "Wrong Answers: $row[test_wrong]";
  echo "<p>";
  echo "Percentage Correct: $perc%";

#2 ShogunWarrior

  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 09:46 PM

I think the best thing is to get a free PHP graph class and use it to display a nice graph.
That way you won't be re-inventing code and coding what someone's put time into, I found one here:

It's open source and free.

Here's an example graph from it:
Posted Image
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 GingerRobot

  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 09:47 PM

if you do want to do it yourself, you'll need to look into using the GD library functions.

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 13 July 2006 - 09:53 PM

If you just show %correct for a single student then a pie is ideal.

If you want to show all questions and the % of students who got each correct then use a column chart with a column for each question
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 realjumper

  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 13 July 2006 - 10:10 PM

Great, thank you all for your help.....I think a bar graph would be the way to go for each result, and a pie chart for the total at the end of the test. What I mean is.... After each question, once the user has selected one four possible answers, the new question appears as well as whether they got the previous question right or wrong and a running total of the number of right and wrong answers so far. So, a bar graph that reflects this progress would be good.....do you think?

Once they complete the test, perhaps a pie chart as well as the total results bar graph of right and wrong would be good. I could also supply a link so that the student could review his errors.

That sounds like a plan ;-)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users