Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to save the Dynamic Piechart in jsp
12-14-2011, 05:18 PM
Post: #1
Tongue How to save the Dynamic Piechart in jsp
This is the continuation of previous tutorial about creating dynamic chart in jsp,One Difference is here we create and save the chart in localdisk and show it on the page see the code below

<%@ page import="java.awt.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import ="org.jfree.data.general.*"%>
<%
final DefaultPieDataset data = new DefaultPieDataset();
data.setValue("A", new Double(10.0));
data.setValue("B", new Double(20.0));
data.setValue("C", new Double(30.0));

JFreeChart chart = ChartFactory.createPieChart
("Pie Chart ", data, true, true, false);

try {
final ChartRenderingInfo info = new
ChartRenderingInfo(new StandardEntityCollection());
final File file1 = new File("c://piechart.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
} catch (Exception e) {
out.println(e);
}
%>


Quote:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<IMG SRC="c:/piechart.png" WIDTH="600" HEIGHT="400"
BORDER="0" USEMAP="#chart">
</body>
</html>

Here we create the file as "final File file1 = new File("c://piechart.png");"
and use the save method as ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
and finally we show the image in the page using <IMG SRC="c:/piechart.png" WIDTH="600" HEIGHT="400"
BORDER="0" USEMAP="#chart"> that's it you have mastered in creating chart in jsp any doubt ask us.

Happy coding.
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
Its My Birthday! Dynamic Chart In Jsp/Create chart in jsp Part-1 rajasri 0 279 12-13-2011 03:40 AM
Last Post: rajasri
Thumbs Up Dynamic Chart In Jsp Part-2 rajasri 0 313 12-13-2011 03:36 AM
Last Post: rajasri
Tongue Dynamic PieChart in Jsp rajasri 0 363 12-13-2011 01:49 AM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)


WE will share important jobs and updates on facebook so like us to get updates