swing - I need to create a XYLineChart with values from database (Java(Mysql) -
i need create xylinechart
values database.
i see this:
public class test { public static void main(string[] args) { xyseries series1 = new xyseries("lions"); series1.add(20, 10); series1.add(40, 20); series1.add(70, 50); xyseries series2 = new xyseries("rabbits"); series2.add(20, 30); series2.add(40, 40); series2.add(70, 10); xyseriescollection xydataset = new xyseriescollection(); xydataset.addseries(series1); xydataset.addseries(series2); jfreechart chart = chartfactory.createxylinechart("weight","kg","numbers",xydataset,plotorientation.vertical,true,false,false); chart.setbackgroundpaint(color.yellow); xyplot plot = (xyplot) chart.getplot(); plot.setbackgroundpaint (color.white); plot.setdomaingridlinepaint (color.green); plot.setrangegridlinepaint (color.orange); plot.setaxisoffset (new rectangleinsets(50, 0, 20, 5)); plot.setdomaincrosshairvisible(true); plot.setrangecrosshairvisible (true); xylineandshaperenderer renderer = (xylineandshaperenderer) plot.getrenderer(); renderer.setbaseshapesvisible(true); renderer.setbaseshapesfilled (true); chartframe frame = new chartframe("chartframe", chart); frame.setsize (450, 250); frame.setvisible(true); } }
but don't know how fetch data database , show them on graph.
with single line graph can connect database, several don't know.
can me? need help, please.
you might want take topic: multiple graphs in multiple figures using jfreechart. in answer described how work jfreechart
, swingworker
make time consuming tasks (like database calls) in background thread , update swing components (in case chart) in event dispatch thread swing components creation , update should take place.
having said should database calls within doinbackground()
method publishing interim results through publish()
method , adding chart within process()
method.
about database call should have jdbc technology. there official trails here:
depending on database engine using there tutorials too, google "jdbc + used dbms" (e.g.: jdbc + mysql, jdbc + postgresql, jdbc + sqlite, etc.). here one:
Comments
Post a Comment