| | |
having problem for display the piechart in JSP
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2006
Posts: 2
Reputation:
Solved Threads: 0
i calling the method to display in web browser using JSP....ii have create the piechart using java code and save it ask JPEG......i just want to use JSP to calling and dispaly the method and display the JPEG pie chart in web browser.....
anyone who can help me here i'm very appriaciate it....
thanks you.......
--------------------------------------------------------------------------------
this is my StoreData.java file ....this is my java file that create pie chart and the data is calling from db4o database.....
-----------------------------------------------------------------------------------
package com;
import java.io.File;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import org.jfree.chart.*;
import org.jfree.data.general.*;
public class StoreData{
private static final long serialVersionUID = 1L;
private final static String filename = "C:\\CountryPieChart.yap";
public static String getFname()
{
return "C:\\CountryPieChart.jpg";
}
public static void main(String[] args){
//Delete the existing file
new File(filename).delete();
ObjectContainer db=Db4o.openFile(filename);
try {
StoreAllData();
retrieveAllData();
} finally{
db.close(); //Close the database
}
}
public static void StoreAllData() {
//Delete the existing file
new File(filename).delete();
ObjectContainer db = Db4o.openFile(filename);
//Add data to the database
CountryPeople countryName_1 = new CountryPeople("Malaysia", 100);
CountryPeople countryName_2 = new CountryPeople("New Z", 200);
CountryPeople countryName_3 = new CountryPeople("UK", 300);
CountryPeople countryName_4 = new CountryPeople("Thailand", 400);
CountryPeople countryName_5 = new CountryPeople("Singapore", 50);
//set the value to database
db.set(countryName_1);
db.set(countryName_2);
db.set(countryName_3);
db.set(countryName_4);
db.set(countryName_5);
}
public static void retrieveAllData() {
//Open db
ObjectContainer db = Db4o.openFile(filename);
//Retrieve via empty object
CountryPeople cName = new CountryPeople(null, 0);
ObjectSet result = db.get(cName);
DefaultPieDataset dataset = new DefaultPieDataset();
//retrieve the data from database
while(result.hasNext()) {
CountryPeople obj = (CountryPeople) result.next();
dataset.setValue(obj.getName(), obj.getValue());
//System.out.println(result.next());
}
//Create pie chart
JFreeChart chart = ChartFactory.createPieChart(
"Sample Chart",
dataset,
true,
true,
false);
try {
//save the pie chart as JPEG file
ChartUtilities.saveChartAsJPEG(new File("C:\\CountryPieChart.jpg"), chart, 500, 300);
} catch(Exception e) {
System.out.println("Problem for creating chart");
}
}
}
----------------------------------------------------------------------------------
this is my jsp coding .... i dont know what is the problem.........coz i very new for jsp and java............thanks....
---------------------------------------------------------------------------------
<%@page import org.jfree.data.general.PieDataset %>
<jsp:useBean id="myStoreData" class="com.StoreData" scope="page"/>
<html>
<head><title>Testing Displaying</title>
</head>
<body>
<b>Testing Display Page</b>
<img src="<jsp:getProperty name="myStoreData" property="fname" />" />
</body>
</html>
---------------------------------------------------------------------------------
anyone who can help me here i'm very appriaciate it....
thanks you.......
--------------------------------------------------------------------------------
this is my StoreData.java file ....this is my java file that create pie chart and the data is calling from db4o database.....
-----------------------------------------------------------------------------------
package com;
import java.io.File;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import org.jfree.chart.*;
import org.jfree.data.general.*;
public class StoreData{
private static final long serialVersionUID = 1L;
private final static String filename = "C:\\CountryPieChart.yap";
public static String getFname()
{
return "C:\\CountryPieChart.jpg";
}
public static void main(String[] args){
//Delete the existing file
new File(filename).delete();
ObjectContainer db=Db4o.openFile(filename);
try {
StoreAllData();
retrieveAllData();
} finally{
db.close(); //Close the database
}
}
public static void StoreAllData() {
//Delete the existing file
new File(filename).delete();
ObjectContainer db = Db4o.openFile(filename);
//Add data to the database
CountryPeople countryName_1 = new CountryPeople("Malaysia", 100);
CountryPeople countryName_2 = new CountryPeople("New Z", 200);
CountryPeople countryName_3 = new CountryPeople("UK", 300);
CountryPeople countryName_4 = new CountryPeople("Thailand", 400);
CountryPeople countryName_5 = new CountryPeople("Singapore", 50);
//set the value to database
db.set(countryName_1);
db.set(countryName_2);
db.set(countryName_3);
db.set(countryName_4);
db.set(countryName_5);
}
public static void retrieveAllData() {
//Open db
ObjectContainer db = Db4o.openFile(filename);
//Retrieve via empty object
CountryPeople cName = new CountryPeople(null, 0);
ObjectSet result = db.get(cName);
DefaultPieDataset dataset = new DefaultPieDataset();
//retrieve the data from database
while(result.hasNext()) {
CountryPeople obj = (CountryPeople) result.next();
dataset.setValue(obj.getName(), obj.getValue());
//System.out.println(result.next());
}
//Create pie chart
JFreeChart chart = ChartFactory.createPieChart(
"Sample Chart",
dataset,
true,
true,
false);
try {
//save the pie chart as JPEG file
ChartUtilities.saveChartAsJPEG(new File("C:\\CountryPieChart.jpg"), chart, 500, 300);
} catch(Exception e) {
System.out.println("Problem for creating chart");
}
}
}
----------------------------------------------------------------------------------
this is my jsp coding .... i dont know what is the problem.........coz i very new for jsp and java............thanks....
---------------------------------------------------------------------------------
<%@page import org.jfree.data.general.PieDataset %>
<jsp:useBean id="myStoreData" class="com.StoreData" scope="page"/>
<html>
<head><title>Testing Displaying</title>
</head>
<body>
<b>Testing Display Page</b>
<img src="<jsp:getProperty name="myStoreData" property="fname" />" />
</body>
</html>
---------------------------------------------------------------------------------
![]() |
Similar Threads
- Horizontal lines across display (Monitors, Displays and Video Cards)
- Laptop LCD Display Problem (Monitors, Displays and Video Cards)
- Problem with removing Display card drivers (Windows NT / 2000 / XP)
- GAteway Solo 5150 Laptop Problem (Troubleshooting Dead Machines)
- GAteway Solo 5150 Laptop Problem (Monitors, Displays and Video Cards)
- problem with displaying in HANDLE C.. (C)
- Wierd Problem please help! (Windows NT / 2000 / XP)
- Desktop background hijacked-NEW Problem (Web Browsers)
- Display not working right---not centered (Windows 95 / 98 / Me)
Other Threads in the JSP Forum
- Previous Thread: How to send an action to servlet through hyperlink and display the data on to jsp.
- Next Thread: Regular Expression
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write





