dcsimg
Graphs in Applet
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Abdul_Basheer
Posted On:   Tuesday, March 19, 2002 09:32 PM

How do i draw graphs / charts like bar chart or pie chart on an applet whose data comes from a servlet?

Re: Graphs in Applet

Posted By:   David_Gilbert  
Posted On:   Thursday, June 6, 2002 03:36 AM

You may be able to develop a solution using JFreeChart:


http://www.object-refinery.com/jfreechart/index.html


The source code is free (GNU LGPL) and has been used successfully by many developers in applications, applets and servlets.


Regards,


Dave Gilbert
JFreeChart Project Leader

Re: Graphs in Applet

Posted By:   Jaume_Ba  
Posted On:   Friday, April 5, 2002 02:41 PM

RChart is an applet that can read data from a URL (which can be a servlet):

http://www.java4less.com/charts_e.htm

Re: Graphs in Applet

Posted By:   Guanglin_du  
Posted On:   Thursday, March 21, 2002 10:44 PM

Dear Abdul,

In your case, I’m afraid, you have to learn how Applet-Servlet communicate and Java3D programming as well.


You can refer to
Dennis J Bouvier’s excellent tutorial (PDF format) “Getting Started with the Java 3D(TM) API”at http://java.sun.com/products/javamedia/3d/collateral for Java3D programming.


As of Applet-Servlet communication programming, the following code lines I’m using in my project are for Servlet and Applet, respectively


The complete Servlet code:


import java.io.*;

import java.net.*;

import javax.servlet.ServletInputStream;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class TraceServlet extends HttpServlet {

// Handle the HTTP POST method.

public void doPost (HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out;

String title = "TraceServlet Output";

String userQuery = request.getQueryString();

//Get the user's IP & the PC's name

String userIP = request.getRemoteAddr();

InetAddress inet = InetAddress.getByName(userIP);

String userID = inet.getHostName();

// System.out.println();

System.out.println("The POSTed tracer: "+userQuery+".");

// System.out.println("userIP = " + userIP);

// System.out.println("userID = " + userID);

ServletInputStream in = request.getInputStream();

int i = in.read();

while (i != -1) {

System.out.print((char) i);

i = in.read();

}

}

}



The Applet code fragment to write to Servlet and read from Servlet response:

try {

URL testServlet = new URL(location + "MeshServlet?myMesh");

URLConnection servletConnection = testServlet.openConnection();

//Inform the connection that we will send output and accept input

servletConnection.setDoOutput(true);

servletConnection.setDoInput(true);

// Don't use a cached version of URL connection.

servletConnection.setUseCaches(false);

servletConnection.setDefaultUseCaches(false);

//POST the request data (html form encoded)

PrintStream out = new PrintStream(servletConnection.getOutputStream());

out.println(URLEncoder.encode("mesh")+"="+URLEncoder.encode("WireFrame"));

out.close();

//Read the POST response data

InputStream in = servletConnection.getInputStream();

// InputStreamReader inReader = new InputStreamReader(in);

int i = in.read();

while (i != -1) {

i = in.read();

}

in.close();

} catch (Throwable t) {

t.printStackTrace();

}



Hope they are of help for you. Regards.
About | Sitemap | Contact