JFreeChart在JSP中将百分比添加到PieChart
这是我在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
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()
));