You can use RRDTool with the sql// pseudo datasource as defined in the manual here.
This is rather complex, but allows the use of the rrdtool graph
command with external DBI-based SQL queries in the DEF declaration. In this you can specify connection criteria, the fields holding the timestamp and value, and any additional WHERE clauses for the SQL query.
Performance is not as good as with native RRD files of course.
EG:
DEF:myvar=sql//mysql/host=127.0.0.1/dbname=rrd/username=rrd/password=passwd//RRDValue/UnixTimeStamp/value/RRDKeyID=1141942900757789274:min:AVERAGE
See the manual page for details.