Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JFreeChart在JSP中将百分比添加到PieChart_Jsp_Jfreechart_Pie Chart - Fatal编程技术网

JFreeChart在JSP中将百分比添加到PieChart

JFreeChart在JSP中将百分比添加到PieChart,jsp,jfreechart,pie-chart,Jsp,Jfreechart,Pie Chart,这是我在JSP中创建PieChart的代码 Connection conn = DBConnection.getConnection(); String strQuery = "SELECT keyword,count(*) from paper_keywords group by keyword"; PreparedStatement preparedStatement = conn.prepareStatement(strQuery); ResultSet rs = preparedSt

这是我在JSP中创建PieChart的代码

Connection conn = DBConnection.getConnection(); 

String strQuery = "SELECT keyword,count(*) from paper_keywords group by keyword";
PreparedStatement preparedStatement = conn.prepareStatement(strQuery);
ResultSet rs = preparedStatement.executeQuery();

DefaultPieDataset pieDataset = new DefaultPieDataset();
while(rs.next())
{ 
    pieDataset.setValue(rs.getString(1),rs.getInt(2));
}
rs.close();
preparedStatement.close();  

JFreeChart chart = ChartFactory.createPieChart ("Popular Keywords", pieDataset, true,true,true);

try {
    final ChartRenderingInfo info = new ChartRenderingInfo (new    StandardEntityCollection());


String test = getServletContext().getRealPath("/");
final File file1 = new File(test+"chart/areachart.png");

ChartUtilities.saveChartAsPNG(file1, chart, 550, 400, info);
} 
catch (Exception e) {
out.println(e);
}
稍后我将在jsp页面中使用它:

<IMG SRC="../chart/areachart.png" >   

如何在图例中添加百分比?谢谢

计算机可以做到这一点

PiePlot plot = (PiePlot) chart.getPlot();
plot.setLegendLabelGenerator(
    new StandardPieSectionLabelGenerator("{0} {1} {2}"));
政府可以做到这一点

PiePlot plot = (PiePlot) chart.getPlot();
plot.setLegendLabelGenerator(
    new StandardPieSectionLabelGenerator("{0} {1} {2}"));

步骤1:首先从下载jfreechart

步骤2:在构建路径中包含jar文件

步骤3:添加以下代码

 PiePlot plot2 = (PiePlot) chart.getPlot();
       plot2.setLabelGenerator(new StandardPieItemLabelGenerator(
                "{0} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()
            ));

步骤1:首先从下载jfreechart

步骤2:在构建路径中包含jar文件

步骤3:添加以下代码

 PiePlot plot2 = (PiePlot) chart.getPlot();
       plot2.setLabelGenerator(new StandardPieItemLabelGenerator(
                "{0} ({2})", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance()
            ));