com.ouc.cpss.view.EmpSaleChartBuilder.java Source code

Java tutorial

Introduction

Here is the source code for com.ouc.cpss.view.EmpSaleChartBuilder.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ouc.cpss.view;

import com.ouc.cpss.vo.ViewEmpsel;
import java.awt.Font;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
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;

/**
 *
 * @author LIUYIYU
 */

@SuppressWarnings("serial")
public class EmpSaleChartBuilder extends JFrame {
    String title;
    static List<ViewEmpsel> list;//??

    public EmpSaleChartBuilder(String title, List list) {
        super(title);
        this.title = title;
        this.list = list;
        //???
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        this.setContentPane(createPanel()); //?????

    }

    private static CategoryDataset createDataSet() {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (ViewEmpsel ve : list) {
            //?????
            dataset.addValue(ve.getTotalprice(), ve.getEname(), ve.getMon() + "");
        }
        return dataset;
    }

    private static JFreeChart createJFreeChart(CategoryDataset dataset) {
        /**
         * JFreeChart
         */
        //?     
        StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
        //     
        standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
        //    
        standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
        //?     
        standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
        //?   
        ChartFactory.setChartTheme(standardChartTheme);
        //?
        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(????)
        JFreeChart chart = createJFreeChart(createDataSet());
        // JFreeChar?JPanel
        return new ChartPanel(chart);
    }

    public static void main(String[] args) {

    }

}