Java學習筆記之jfreeChart 柱狀圖

來源:互聯網
上載者:User
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);}}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.