1 Attachment(s)
HELP! JFreeChart Displayed on WEB using netbeans
I need help please, thanks in advance...
Well I am using netbeans for programming a data reporting site, I need a chart to represent these data. [I have JFreeChat and JCommon in my netbeans Library].
Well in my I have my main page called "index.jsp" with a button liking to an action[.JAVA] which contains this sample java code then I'll forward it to another page to view the graph... But I don't know yet and haven't found yet how how to apply the JFreeChart Graph to a page using the JAVA [.java] code.
Attachment 4288
The code I used for my button at index.jsp is:<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@page import="java.util.*" %>
<%@page import="com.ti.ffw.Libs.MiscLib.*"%>
<%@page import="java.text.*"%>
<%@page import="java.util.*"%>
<head>
<title>Report</title></head>
<body>
<form method="post" action="/Report/AppServlet?action=StackedBarChart&forward=/index_1.jsp">
<input type="submit" value="Test Button">
</form>
</body> </html>
Could someone please help me. :s: I need it as soon as possible, I am too pressured, sorry.
JAVA CODE
Code:
import org.jfree.ui.*;
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.chart.plot.PlotOrientation;
public class StackedBarChart extends ApplicationFrame {
public StackedBarChart(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
private CategoryDataset createDataset() {
DefaultCategoryDataset result = new DefaultCategoryDataset();
result.addValue(10, "Girls", "Chess");
result.addValue(15, "Boys", "Chess");
result.addValue(17, "Girls", "Cricket");
result.addValue(23, "Boys", "Cricket");
result.addValue(25, "Girls", "FootBall");
result.addValue(20, "Boys", "FootBall");
result.addValue(40, "Girls", "Badminton");
result.addValue(30, "Boys", "Badminton");
result.addValue(35, "Girls", "Hockey");
result.addValue(32, "Boys", "Hockey");
return result;
}
private JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createStackedBarChart(
"Stacked Bar Chart", "Games", "No. of students", dataset,
PlotOrientation.VERTICAL, true, true, false);
return chart;
}
public static void main(final String[] args) {
final StackedBarChart demo = new StackedBarChart("Stacked Bar Chart");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}