You might want to take a look to this topic: Multiple graphs in multiple figures using jFreeChart. In the answer is described how to work with JFreeChart
and SwingWorker
to make time consuming tasks (like database calls) in a background thread and update Swing components (in this case the chart) in the Event Dispatch Thread where Swing components creation and update should take place.
Having said this you should do database calls within doInBackground()
method publishing interim results through publish()
method and adding those to the chart within process()
method.
About database call you should have a look to JDBC technology. There are official trails here:
Depending on what database engine are you using there are some good tutorials too, just google for "jdbc + used DBMS" (e.g.: jdbc + mysql, jdbc + postgresql, jdbc + sqlite, etc.). Here is a really good one: