Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic PieChart in Jsp
12-13-2011, 01:49 AM (This post was last modified: 12-20-2011 12:29 AM by rajasri.)
Post: #1
Tongue Dynamic PieChart in Jsp
Today We are going to learn how to create a dynamic pie-chart in jsp page.
It is a easy way to create chart in java using jfree chart to more about that see previous posts about charts lets create the chart see the example 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.*"%>
<%@ page import = "org.jfree.chart.plot.PiePlot"%>
<%@ page import ="java.io.OutputStream"%>

<%
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());
OutputStream out1 = response.getOutputStream();
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(false);
plot.setLabelGap(0.02);
ChartUtilities.writeChartAsPNG(out1, chart, 600, 400);
}
catch (Exception e)
{
out.println(e);
}

%>


In this example first you have to create an object for DefaultPieDataset and set the values you want to show in chart then use JFreeChart chart = ChartFactory.createPieChart("Pie Chart ", data, true, true, false); to create piechart,use rendering if you want to set your own color,finally ChartUtilities.writeChartAsPNG(out1, chart, 600, 400); is used to write the chart in the jsp page.

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
Tongue How to save the Dynamic Piechart in jsp rajasri 0 215 12-14-2011 05:18 PM
Last Post: rajasri
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

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