gpt4 book ai didi

java - 在饼图中显示百分比值

转载 作者:行者123 更新时间:2023-12-04 05:20:15 28 4
gpt4 key购买 nike

我在 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
}

最佳答案

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

plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"));

关于java - 在饼图中显示百分比值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13768505/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com