in reply to GD Graph
You say that your script fails, but not how it fails. Do you see error messages? Does it not do what you want? If so, what does it do and what do you want it to do?
Essentially, you're tackling two problems: pulling data from a database and building a chart. Try isolating the code to perform each problem separately.
Firstly, query the database and check you have the data structures you expect in $projectname, @dat and $pno using Data::Dumper and warn in your foreach loop.
Secondly pass data of the form you expect to retrieve from the database to GD::Graph::bars and see what happens.