I need to create a XYLineChart
with values from 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 to fetch data from the database and show them on the graph.
With a single line graph I can connect to the database, but several don't know.
Can anyone help me? I really need help, please.