Hi,
can any body suggest me code for (jfreechart optional)scatterplot(dot plot)graph in jsp.
i try it in java its working fine,but i want it in jsp,the data should be from database,
iam adding my code
!----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Shape;
import java.util.*;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.ShapeUtilities;
import java.sql.*;
public class SPlotfinal extends ApplicationFrame {
public SPlotfinal(String s) {
super(s);
JPanel jpanel = createDemoPanel();
jpanel.setPreferredSize(new Dimension(640, 480));
add(jpanel);
}
public static JPanel createDemoPanel() {
JFreeChart jfreechart = ChartFactory.createScatterPlot(
"Dot Plot ", "X", "Y", samplexydataset2(),
PlotOrientation.VERTICAL, true, true, false);
Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
xyPlot.setDomainCrosshairVisible(true);
xyPlot.setRangeCrosshairVisible(true);
XYItemRenderer renderer = xyPlot.getRenderer();
renderer.setSeriesShape(0, cross);
renderer.setSeriesPaint(0, Color.red);
return new ChartPanel(jfreechart);
}
private static XYDataset samplexydataset2() {
int cols = 20;
int rows = 20;
double[][] values = new double[cols][rows];
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
XYSeries series = new XYSeries("GRAPH");
Random rand = new Random();
try
{
String connectionURL = "jdbc:mysql://localhost:3306/mysql";
Connection con;
Class.forName("com.mysql.jdbc.Driver");
// Get a Connection to the database
con = DriverManager.getConnection(connectionURL, "root", "root");
//Add the data into the database
String sql = "SELECT COUNT FROM GRAPH";
Statement stm = con.createStatement();
stm.executeQuery(sql);
ResultSet rs= stm.getResultSet();
while (rs.next ()){
int count=rs.getInt(1);
System.out.println(count);
String sql1 = "SELECT XAXIS,YAXIS FROM GRAPH";
Statement stm1 = con.createStatement();
stm1.executeQuery(sql1);
ResultSet rs1= stm1.getResultSet();
while (rs1.next ()){
for(int k=0; k<=count; k++)
{
double x = rs1.getInt(1);
double y = rs1.getInt(2);
series.add(x, y);
}
}
}
}
catch(Exception e){
System.out.println(e);
}
xySeriesCollection.addSeries(series);
return xySeriesCollection;
}
public static void main(String args[]) {
SPlotfinal scatterplotdemo4 = new SPlotfinal("GRAPH-KALYANI");
scatterplotdemo4.pack();
RefineryUtilities.centerFrameOnScreen(scatterplotd emo4);
scatterplotdemo4.setVisible(true);
}
}
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
plz help me
thanks in advance,