aspose file tools*
The moose likes Applets and the fly likes Creating Charts in Applets using Data from Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Creating Charts in Applets using Data from Database" Watch "Creating Charts in Applets using Data from Database" New topic
Author

Creating Charts in Applets using Data from Database

carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

Hi, i am creating Pie chart and Bar graphs using the data from the database. For that Applets are designed which draw Pie chart and Bar graph for me. now i have to pass data from database tables as parameters. Can anybody suggest me how do i do this.

my html file that calls applet is



As you can see i tried passing the values from javascript (where javascript calls a servlet and get database value) . But by the time servlet fetches data from database the applet code runs and calls Pie3D.class and dispaly error as &{amount1} and &{amount2} do not have values.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
While there are intricate and brittle ways of using JavaScript for this, those wouldn't work when using PARAM tags. The easiest way would be to make the HTML page a JSP page, and in the JSP page to use a backing bean that pulls in the values from the DB, and so can populate the PARAM tags right when they are generated. That's much more straightforward than doing anything after the page has been served.


Ping & DNS - my free Android networking tools app
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

Thanks for the reply. Can i add database connection in my applet and put the data directly into getParameter() inside the applet.
And i am currently trying that but the pie being displayed is of one color ... database data has got no effect on the Pie display.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
It's generally considered bad design for applets to connect directly to databases for security reasons (and if you were to go that route, then getParameter would not be part of the solution).

We can't comment on what might be going wrong with your current approach since we don't know how that works.

If it's really just two values that you need, then I think that the approach I mentioned in my previous post would work best.
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

I am trying to design beans now, which i did not do before.



where do i add setters and getters and how do i link the applet parameters to these setters and getters.

Please suggets me.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
Is this class supposed to be used as part of the client (the applet) or as part of the server (the web app)?
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

My scenario is to show daily sales,collection,profit,loss in the form of Pie chart and bar graph, and the figures of these are stored in a table that gets populated everyday .
Therefore i am trying to get these values from that table as a parameter to the applet.

and yes this is part of server.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
If that class runs on the server, then your JSP now needs to use it; check out the jsp:useBean directive. The bean also needs to expose all values that you need to embed in the HTML page through public getter methods. Any decent JSP tutorial covers these steps (in case you haven't used JSP beans before).
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300




I added the getters and setters in the same bean .. as it should be the getters and setters are having the last row fetched from the table... how do i get all the rows fetched in my jsp ... in jsp i am using useBEan and getProperty tag and it fetched me last row from the table.

Can you please suggest me some JSP tutorial.

Thanks for your time.
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

finally i am able to pass the parameters to the applet param tag



But here the number of parameters are specific.
Suppose 3 more rows get added into database then i need to change my bean class which has all the values exposed that get embedded in the html page.
how can i make my bean,param tags in the html dynamic so that if more number of rows get added in table then i need not change the bean, html page.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
You can add a parameter that indicates how many values you're passing along. Then the applet can iterate from 1 to that number to retrieve all parameters and their values:
carina caoor
Ranch Hand

Joined: Jun 23, 2007
Posts: 300

But how do i make bean dynamic .. so that it adds the setters and getters on its own based on the rows fetched from database.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41477
    
  51
You'll have to make your code independent of the actual names:

The JSP would then iterate over all entries in the map and create PARAM tags accordingly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Charts in Applets using Data from Database