如何在同一次运行中显示饼图?

时间:2016-04-13 12:12:27

标签: java jsp jfreechart pie-chart display

我正在尝试在项目运行时制作饼图。饼图的值正在计算并由类别无线电的函数rq返回。 饼图在运行代码时形成,但只有在再次构建项目时才会显示它们。因此显示的饼图具有prvious run的值。如果我运行代码并制作饼图,这些将在我构建项目并再次运行时显示。因此存在滞后。如何显示当前的饼图而不在同一次运行中再次构建项目?请帮帮我。

<jsp:useBean id="radioques" scope="page" class="abc.radioques" />
<%
String q[] = new String[44];
int j;
for (int i = 0; i < 44; i++) {
    j = 0;
    j = i + 1;
    q[i] = request.getParameter("question" + j);
}
radioques.rq(q);
%>
<jsp:useBean id="music" scope="page" class="abc.music" />

<%@ page import="java.io.*" %> 
<%@ page import="org.jfree.chart.ChartFactory" %> 
<%@ page import="org.jfree.chart.JFreeChart" %> 
<%@ page import="org.jfree.chart.plot.PiePlot3D" %> 
<%@ page import="org.jfree.data.general.DefaultPieDataset" %> 
<%@ page import="org.jfree.chart.ChartUtilities" %> 
<%@ page import="java.lang.*" %>
<%@ page import="java.awt.Font"%>

<%@ page import="org.jfree.chart.ChartPanel"%>
<%@ page import="org.jfree.chart.JFreeChart"%>
<%@ page import="org.jfree.chart.labels.*"%>
<%@ page import="org.jfree.chart.plot.MultiplePiePlot"%>
<%@ page import="org.jfree.chart.plot.PiePlot"%>
<%@ page import="org.jfree.data.category.CategoryDataset"%>
<%@ page import="org.jfree.data.general.DatasetUtilities"%>
<%@ page import="org.jfree.util.TableOrder"%>

<%@ page import="abc.radioques" %>

<%
radioques r = new radioques();
double temp[] = new double[5];
temp = r.rq(q);
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("O+ = " + Math.round(temp[0]), (double) (temp[0]));
dataset.setValue("O- = " + Math.round(100 - temp[0]), (100 - (double) (temp[0])));

JFreeChart chart = ChartFactory.createPieChart3D(
        "Openness", // chart title                   
        dataset, // data 
        true, // include legend                   
        true,
        false);

final PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(270);
plot.setForegroundAlpha(0.60f);
plot.setInteriorGap(0.02);
int width = 640; /* Width of the image */

int height = 480; /* Height of the image */

File pieChart3D = new File("C:/Users/Prashant/Documents/NetBeansProjects/WebApplication4/web/piecharts/pie3D.jpeg");
ChartUtilities.saveChartAsJPEG(pieChart3D, chart, width, height);

DefaultPieDataset dataset1 = new DefaultPieDataset();
dataset1.setValue("C+ = " + Math.round(temp[1]), (double) (temp[1]));
dataset1.setValue("C- = " + Math.round(100 - temp[1]), (100 - (double) (temp[1])));

JFreeChart chart1 = ChartFactory.createPieChart3D(
        "Conscientiousness", // chart title                   
        dataset1, // data 
        true, // include legend                   
        true,
        false);

final PiePlot3D plot1 = (PiePlot3D) chart1.getPlot();
plot1.setStartAngle(270);
plot1.setForegroundAlpha(0.60f);
plot1.setInteriorGap(0.02);
int width1 = 640; /* Width of the image */

int height1 = 480; /* Height of the image */

File pieChart3D1 = new File("C:/Users/Prashant/Documents/NetBeansProjects/WebApplication4/web/piecharts/pie3D1.jpeg");
ChartUtilities.saveChartAsJPEG(pieChart3D1, chart1, width1, height1);

DefaultPieDataset dataset2 = new DefaultPieDataset();
dataset2.setValue("E+ = " + Math.round(temp[2]), (double) (temp[2]));
dataset2.setValue("E- = " + Math.round(100 - temp[2]), (100 - (double) (temp[2])));

JFreeChart chart2 = ChartFactory.createPieChart3D(
        "Extraversion", // chart title                   
        dataset2, // data 
        true, // include legend                   
        true,
        false);

final PiePlot3D plot2 = (PiePlot3D) chart2.getPlot();
plot2.setStartAngle(270);
plot2.setForegroundAlpha(0.60f);
plot1.setInteriorGap(0.02);
int width2 = 640; /* Width of the image */

int height2 = 480; /* Height of the image */

File pieChart3D2 = new File("C:/Users/Prashant/Documents/NetBeansProjects/WebApplication4/web/piecharts/pie3D2.jpeg");
ChartUtilities.saveChartAsJPEG(pieChart3D2, chart2, width2, height2);

DefaultPieDataset dataset3 = new DefaultPieDataset();
dataset3.setValue("A+ = " + Math.round(temp[3]), (double) (temp[3]));
dataset3.setValue("A- = " + Math.round(100 - temp[3]), (100 - (double) (temp[3])));

JFreeChart chart3 = ChartFactory.createPieChart3D(
        "Agreeableness", // chart title                   
        dataset3, // data 
        true, // include legend                   
        true,
        false);

final PiePlot3D plot3 = (PiePlot3D) chart3.getPlot();
plot3.setStartAngle(270);
plot3.setForegroundAlpha(0.60f);
plot3.setInteriorGap(0.02);
int width3 = 640; /* Width of the image */

int height3 = 480; /* Height of the image */

File pieChart3D3 = new File("C:/Users/Prashant/Documents/NetBeansProjects/WebApplication4/web/piecharts/pie3D3.jpeg");
ChartUtilities.saveChartAsJPEG(pieChart3D3, chart3, width3, height3);
DefaultPieDataset dataset4 = new DefaultPieDataset();
dataset4.setValue("N+ = " + Math.round(temp[4]), (double) (temp[4]));
dataset4.setValue("N- = " + Math.round(100 - temp[4]), (100 - (double) (temp[4])));

JFreeChart chart4 = ChartFactory.createPieChart3D(
        "Neuroticism", // chart title                   
        dataset4, // data 
        true, // include legend                   
        true,
        false);

final PiePlot3D plot4 = (PiePlot3D) chart4.getPlot();
plot4.setStartAngle(270);
plot4.setForegroundAlpha(0.60f);
plot4.setInteriorGap(0.02);
int width4 = 640; /* Width of the image */

int height4 = 480; /* Height of the image */

File pieChart3D4 = new File("C:/Users/Prashant/Documents/NetBeansProjects/WebApplication4/web/piecharts/pie3D4.jpeg");
ChartUtilities.saveChartAsJPEG(pieChart3D4, chart4, width4, height4);

music.selectsongs(temp);


%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Your Personality</title>
    <link rel="stylesheet" type="text/css" href="newcss2.css">
</head>





<body>
    <h1>Your Personality</h1>
    <table>
        <thead>
            <tr>
                <th> Your OCEAN Traits Values</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td class="t1" align="left">
                    <img src="piecharts/pie3D.jpeg" width="342px">
                </td>
                <td class="t1" align="center">
                    <img src="piecharts/pie3D1.jpeg" width="342px">
                </td>
                <td class="t1" align="right">
                    <img src="piecharts/pie3D2.jpeg" width="342px">
                </td>
            </tr>
            <tr>
                <td class="t1" align="left">
                    <img src="piecharts/pie3D3.jpeg" width="342px">
                </td>
                <td class="t1" align="center">
                    <img src="piecharts/pie3D4.jpeg" width="342px">
                </td>
                <td align="middle" align="center">
                    <form name="ocean" action="page3.jsp"  method="POST">
                        <input type="submit" width="100" height="50" name="Next2" value="Next" />
                    </form>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>

0 个答案:

没有答案
相关问题