package com.mengya.test.jfreechart;import java.awt.Font;import javax.swing.JPanel;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartPanel;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.title.TextTitle;import org.jfree.data.category.CategoryDataset;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.ui.ApplicationFrame;/** * JFreeChart出生Swing形式的柱狀圖 * * @author 張明學 * */@SuppressWarnings("serial")public class JfreeChartTest2 extends ApplicationFrame {public JfreeChartTest2(String title) {super(title);this.setContentPane(createPanel());}private static CategoryDataset createDataSet() {DefaultCategoryDataset dataset = new DefaultCategoryDataset();// dataset.setValue(10, "", "管理員");// dataset.setValue(15, "", "市場人員");// dataset.setValue(35, "", "開發人員");// dataset.setValue(12, "", "其他人員");dataset.setValue(10, "aa", "管理員");dataset.setValue(15, "bb", "市場人員");dataset.setValue(35, "cc", "開發人員");dataset.setValue(12, "dd", "其他人員");return dataset;}private static JFreeChart createJFreeChart(CategoryDataset dataset) {/** * 構建JFreeChart */// JFreeChart jfreeChart// =ChartFactory.createBarChart("某公司組織圖","人員分布","人員數量",dataset,PlotOrientation.VERTICAL,false,false,false);// JFreeChart jfreeChart// =ChartFactory.createBarChart("某公司組織圖","人員分布","人員數量",dataset,PlotOrientation.VERTICAL,true,false,false);JFreeChart jfreeChart = ChartFactory.createBarChart3D("某公司組織圖","人員分布", "人員數量", dataset, PlotOrientation.VERTICAL, true, false,false);/** * 設定JFreeChart的屬性 */jfreeChart.setTitle(new TextTitle("某公司組織構圖", new Font("宋體", Font.BOLD+ Font.ITALIC, 20)));CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();CategoryAxis categoryAxis = plot.getDomainAxis();categoryAxis.setLabelFont(new Font("仿宋", Font.ROMAN_BASELINE, 12));return jfreeChart;}public static JPanel createPanel() {JFreeChart chart = createJFreeChart(createDataSet());return new ChartPanel(chart);}public static void main(String[] args) {JfreeChartTest2 chart = new JfreeChartTest2("某公司組織圖");chart.pack();chart.setVisible(true);}}