
hi, can anybody provide me code for ScatterPlot using jsp.
thanks,

<%@page import="java.awt.RenderingHints"%>
<%@page import="org.jfree.chart.ChartFrame"%>
<%@page import=" org.jfree.chart.ChartPanel"%>
<%@page import=" org.jfree.chart.JFreeChart"%>
<%@page import=" org.jfree.chart.axis.NumberAxis"%>
<%@page import=" org.jfree.chart.plot.FastScatterPlot"%>
<%@page import=" org.jfree.ui.ApplicationFrame"%>
<%@page import=" org.jfree.ui.RefineryUtilities"%>
<%
int COUNT = 500000;
float[][] data = new float[2][COUNT];
for (int i = 0; i < data[0].length; i++) {
final float x = (float) i + 100000;
data[0][i] = x;
data[1][i] = 100000 + (float) Math.random() * COUNT;
}
final NumberAxis domainAxis = new NumberAxis("X");
domainAxis.setAutoRangeIncludesZero(false);
final NumberAxis rangeAxis = new NumberAxis("Y");
rangeAxis.setAutoRangeIncludesZero(false);
final FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis);
final JFreeChart chart = new JFreeChart(" Scatter Graph ", plot);
chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ChartFrame frame1=new ChartFrame("Scatter Chart",chart);
frame1.setVisible(true);
frame1.setSize(500,300);
%>

hi, thanks a lot for your code. i used this code and for data i used database connections. but iam not getting the graph.
plz find out my mistake..
<%@page import="java.awt.RenderingHints"%>
<%@page import="org.jfree.chart.ChartFrame"%>
<%@page import=" org.jfree.chart.ChartPanel"%>
<%@page import=" org.jfree.chart.JFreeChart"%>
<%@page import=" org.jfree.chart.axis.NumberAxis"%>
<%@page import=" org.jfree.chart.plot.FastScatterPlot"%>
<%@page import=" org.jfree.ui.ApplicationFrame"%>
<%@page import=" org.jfree.ui.RefineryUtilities"%>
<%@page import="java.sql.*"%>
<%
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 ()){
double[][] data = new double[2][count];
for(int k=0; k<=data[0].length; k++)
{
data[0][k] = rs1.getInt(1);
data[1][k] = rs1.getInt(2);
}
final NumberAxis domainAxis = new NumberAxis("X");
domainAxis.setAutoRangeIncludesZero(false);
final NumberAxis rangeAxis = new NumberAxis("Y");
rangeAxis.setAutoRangeIncludesZero(false);
final FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis);
final JFreeChart chart = new JFreeChart(" Scatter Graph ", plot);
chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ChartFrame frame1=new ChartFrame("Scatter Chart",chart);
frame1.setVisible(true);
frame1.setSize(500,300);
}
}
}
catch(Exception e){
System.out.println(e);
}
%>
thanks,
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.