Java 饼形图

package pie; import java.awt.Font; import java.awt.RenderingHints; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.ui.RefineryUtilities; public class Jfree { public static void createPieChart() { // 通过工程创建3D饼图 JFreeChart pieChart = ChartFactory.createPieChart("最受欢迎的偶像剧2008-2010", createDataset(), true, true, false); pieChart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); // 得到3D饼图的plot对象 PiePlot piePlot = (PiePlot) pieChart.getPlot(); // 设置透明度 piePlot.setForegroundAlpha(0.5f); piePlot.setLabelFont((new Font("宋体", Font.PLAIN, 12))); // 设置标题字体 pieChart.getTitle().setFont(new Font("隶书", Font.BOLD, 20)); // 设置图例类别字体 pieChart.getLegend().setItemFont(new Font("宋体", Font.BOLD, 14)); ChartFrame frame = new ChartFrame("TestPieChart", pieChart); frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); } public static DefaultPieDataset createDataset() { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("霹雳MIT", 2.80); pieDataset.setValue("桃花爱无敌", 3.63); pieDataset.setValue("恶作剧之吻 ", 2.84); return pieDataset; } public static void main(String[] args) { createPieChart(); } } Java 饼形图_第1张图片

你可能感兴趣的:(Java 饼形图)