few things that come to mind...
1) try the query in phpmyadmin, what results does it return?
2) this line:
if (!$sql) die('Invalid query: ' . mysql_error());
doesn't do what you probably want it to do. it just does a boolean evaluation of the query as a string which will always return true, if the string is not empty.
3) reduce to the minimum.
4) var_dump($data)
5) var_dump($chart)