2

png我进行了编码以在格式文件中创建饼图文件;饼图显示百分比,但它位于文件的底部。我希望百分比出现在图表本身中。这是我使用的代码:

String query = "SELECT name,flag from mawarid";

JDBCPieDataset dataset = new JDBCPieDataset(
    "jdbc:oracle:thin:@ 127.0.0.1:1521:XE", "oracle.jdbc.OracleDriver", "", "");

dataset.executeQuery(query);

JFreeChart chart = ChartFactory.createPieChart(
    "Test", dataset, true, true, false);
try {
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLegendLabelGenerator(
        new StandardPieSectionLabelGenerator("{0} {2}"));

    final ChartRenderingInfo info = new ChartRenderingInfo(
        new StandardEntityCollection());
    final File file1 = new File("Chart5.png");
    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

} catch (Exception e) {
    // log exception
}
4

2 回答 2

2

您可以在标签生成器中使用与在图例标签生成器中相同的消息格式:

plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));
于 2012-12-08T02:52:10.960 回答
1

尝试PieLabelDistributorPiePlot.

plot.setLabelDistributor(PieLabelDistributor aDistributor)
于 2012-12-07T19:35:36.197 回答