Search in sources :

Example 21 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project blueseer by blueseerERP.

the class ReconAccount method chartExp.

public void chartExp() {
    expenses = 0;
    try {
        Connection con = DriverManager.getConnection(url + db, user, pass);
        Statement st = con.createStatement();
        ResultSet res = null;
        try {
            DateFormat dfdate = new SimpleDateFormat("yyyy-MM-dd");
            res = st.executeQuery("select posd_acct, ac_desc, sum(posd_netprice * posd_qty) as 'sum' from pos_det " + " inner join pos_mstr on pos_nbr = posd_nbr  " + " inner join ac_mstr on ac_id = posd_acct  " + " where pos_entrydate >= " + "'" + dfdate.format(dcglprevious.getDate()) + "'" + " AND pos_entrydate <= " + "'" + dfdate.format(dcto.getDate()) + "'" + " AND pos_type = 'expense' " + " AND pos_site = " + "'" + ddsite.getSelectedItem().toString() + "'" + " group by posd_acct, ac_desc order by posd_acct desc   ;");
            DefaultPieDataset dataset = new DefaultPieDataset();
            String acct = "";
            while (res.next()) {
                acct = res.getString("ac_desc");
                Double amt = res.getDouble("sum");
                if (amt < 0) {
                    amt = amt * -1;
                }
                expenses += amt;
                if (amt > 0) {
                    dataset.setValue(acct, amt);
                }
            }
            JFreeChart chart = ChartFactory.createPieChart("Expenses For Date Range", dataset, true, true, false);
            PiePlot plot = (PiePlot) chart.getPlot();
            // plot.setSectionPaint(KEY1, Color.green);
            // plot.setSectionPaint(KEY2, Color.red);
            // plot.setExplodePercent(KEY1, 0.10);
            // plot.setSimpleLabels(true);
            PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("$ #,##0.00", new DecimalFormatSymbols(Locale.US)), new DecimalFormat("0%", new DecimalFormatSymbols(Locale.US)));
            plot.setLabelGenerator(gen);
            try {
                ChartUtilities.saveChartAsJPEG(new File(exoincfilepath), chart, (int) (this.getWidth() / 2.5), (int) (this.getHeight() / 2.7));
            // ChartUtilities.saveChartAsJPEG(new File(exoincfilepath), chart, 400, 200);
            } catch (IOException e) {
                MainFrame.bslog(e);
            }
            ImageIcon myicon = new ImageIcon(exoincfilepath);
            myicon.getImage().flush();
            // myicon.getImage().getScaledInstance(400, 200, Image.SCALE_SMOOTH);
            this.chartlabel.setIcon(myicon);
            this.repaint();
        // bsmf.MainFrame.show("your chart is complete...go to chartview");
        } catch (SQLException s) {
            MainFrame.bslog(s);
            bsmf.MainFrame.show(getMessageTag(1016, Thread.currentThread().getStackTrace()[1].getMethodName()));
        } finally {
            if (res != null) {
                res.close();
            }
            if (st != null) {
                st.close();
            }
            con.close();
        }
    } catch (Exception e) {
        MainFrame.bslog(e);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormatSymbols(java.text.DecimalFormatSymbols) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DecimalFormat(java.text.DecimalFormat) Connection(java.sql.Connection) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) IOException(java.io.IOException) BlueSeerUtils.bsParseDouble(com.blueseer.utl.BlueSeerUtils.bsParseDouble) BlueSeerUtils.currformatDouble(com.blueseer.utl.BlueSeerUtils.currformatDouble) JFreeChart(org.jfree.chart.JFreeChart) ParseException(java.text.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) ResultSet(java.sql.ResultSet) PiePlot(org.jfree.chart.plot.PiePlot) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 22 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project blueseer by blueseerERP.

the class ReconAccount method chartBuyAndSell.

public void chartBuyAndSell() {
    try {
        Connection con = DriverManager.getConnection(url + db, user, pass);
        Statement st = con.createStatement();
        ResultSet res = null;
        try {
            DateFormat dfdate = new SimpleDateFormat("yyyy-MM-dd");
            res = st.executeQuery("select pos_type, sum(pos_totamt) as 'sum' from pos_mstr  " + " where pos_entrydate >= " + "'" + dfdate.format(dcglprevious.getDate()) + "'" + " AND pos_entrydate <= " + "'" + dfdate.format(dcto.getDate()) + "'" + " AND pos_type <> 'expense' " + " AND pos_site = " + "'" + ddsite.getSelectedItem().toString() + "'" + " group by pos_type order by pos_type desc   ;");
            DefaultPieDataset dataset = new DefaultPieDataset();
            String acct = "";
            while (res.next()) {
                acct = res.getString("pos_type");
                if (acct.equals("income")) {
                    acct = "misc income";
                }
                Double amt = res.getDouble("sum");
                if (amt < 0) {
                    amt = amt * -1;
                }
                dataset.setValue(acct, amt);
            }
            JFreeChart chart = ChartFactory.createPieChart("Buy / Sell / Misc Income For Date Range", dataset, true, true, false);
            PiePlot plot = (PiePlot) chart.getPlot();
            // plot.setSectionPaint(KEY1, Color.green);
            // plot.setSectionPaint(KEY2, Color.red);
            // plot.setExplodePercent(KEY1, 0.10);
            // plot.setSimpleLabels(true);
            PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("$ #,##0.00", new DecimalFormatSymbols(Locale.US)), new DecimalFormat("0%", new DecimalFormatSymbols(Locale.US)));
            plot.setLabelGenerator(gen);
            try {
                ChartUtilities.saveChartAsJPEG(new File(buysellfilepath), chart, (int) (this.getWidth() / 2.5), (int) (this.getHeight() / 2.7));
            } catch (IOException e) {
                MainFrame.bslog(e);
            }
            ImageIcon myicon = new ImageIcon(buysellfilepath);
            myicon.getImage().flush();
            this.pielabel.setIcon(myicon);
            this.repaint();
        // bsmf.MainFrame.show("your chart is complete...go to chartview");
        } catch (SQLException s) {
            MainFrame.bslog(s);
            bsmf.MainFrame.show(getMessageTag(1016, Thread.currentThread().getStackTrace()[1].getMethodName()));
        } finally {
            if (res != null) {
                res.close();
            }
            if (st != null) {
                st.close();
            }
            con.close();
        }
    } catch (Exception e) {
        MainFrame.bslog(e);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormatSymbols(java.text.DecimalFormatSymbols) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DecimalFormat(java.text.DecimalFormat) Connection(java.sql.Connection) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) IOException(java.io.IOException) BlueSeerUtils.bsParseDouble(com.blueseer.utl.BlueSeerUtils.bsParseDouble) BlueSeerUtils.currformatDouble(com.blueseer.utl.BlueSeerUtils.currformatDouble) JFreeChart(org.jfree.chart.JFreeChart) ParseException(java.text.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) ResultSet(java.sql.ResultSet) PiePlot(org.jfree.chart.plot.PiePlot) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 23 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project mirai-plugin-HRobot by happysnaker.

the class ChartUtil method generateAPieChart.

public static String generateAPieChart(Map<String, Long> dataset, String title) throws IOException {
    try {
        // 如果不使用Font,中文将显示不出来
        Font font = new Font("宋体", Font.BOLD, 15);
        DefaultPieDataset pds = new DefaultPieDataset();
        for (Map.Entry<String, Long> it : dataset.entrySet()) {
            pds.setValue(it.getKey(), it.getValue());
        }
        JFreeChart chart = ChartFactory.createPieChart(title, pds, true, false, true);
        // 设置图片标题的字体
        chart.getTitle().setFont(font);
        // 得到图块,准备设置标签的字体
        PiePlot plot = (PiePlot) chart.getPlot();
        // 设置标签字体
        plot.setLabelFont(font);
        // 设置图例项目字体
        chart.getLegend().setItemFont(font);
        plot.setStartAngle(new Float(3.14f / 2f));
        // 设置plot的前景色透明度
        plot.setForegroundAlpha(0.7f);
        // 设置plot的背景色透明度
        plot.setBackgroundAlpha(0.0f);
        // 设置标签生成器(默认{0})
        // {0}:key {1}:value {2}:百分比 {3}:sum
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}({1})/{2}"));
        // 将内存中的图片写到本地硬盘
        String path = directionPath + UUID.randomUUID() + ".jpg";
        ChartUtilities.saveChartAsJPEG(new File(path), chart, 800, 400);
        return path;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) Map(java.util.Map) File(java.io.File) JFreeChart(org.jfree.chart.JFreeChart) IOException(java.io.IOException)

Example 24 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createRingChart.

/**
 * Creates a ring chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link RingPlot}
 * instance as the plot.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A ring chart.
 */
public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) {
    RingPlot plot = new RingPlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    }
    if (urls) {
        plot.setURLGenerator(new StandardPieURLGenerator());
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) RingPlot(org.jfree.chart.plot.RingPlot) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) RectangleInsets(org.jfree.chart.api.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Example 25 with StandardPieSectionLabelGenerator

use of org.jfree.chart.labels.StandardPieSectionLabelGenerator in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class ChartFactory method createPieChart.

/**
 * Creates a pie chart with default settings.
 * <P>
 * The chart object returned by this method uses a {@link PiePlot} instance
 * as the plot.
 *
 * @param title  the chart title ({@code null} permitted).
 * @param dataset  the dataset for the chart ({@code null} permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param locale  the locale ({@code null} not permitted).
 *
 * @return A pie chart.
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale) {
    PiePlot plot = new PiePlot(dataset);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale));
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    if (tooltips) {
        plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale));
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) MultiplePiePlot(org.jfree.chart.plot.pie.MultiplePiePlot) PiePlot(org.jfree.chart.plot.pie.PiePlot) RectangleInsets(org.jfree.chart.api.RectangleInsets) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator)

Aggregations

StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)71 PiePlot (org.jfree.chart.plot.PiePlot)47 JFreeChart (org.jfree.chart.JFreeChart)31 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)31 DecimalFormat (java.text.DecimalFormat)30 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)25 PieSectionLabelGenerator (org.jfree.chart.labels.PieSectionLabelGenerator)24 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)21 File (java.io.File)17 IOException (java.io.IOException)17 Connection (java.sql.Connection)16 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 Statement (java.sql.Statement)16 DateFormat (java.text.DateFormat)16 SimpleDateFormat (java.text.SimpleDateFormat)16 ImageIcon (javax.swing.ImageIcon)16 Font (java.awt.Font)14 BlueSeerUtils.currformatDouble (com.blueseer.utl.BlueSeerUtils.currformatDouble)13 TextTitle (org.jfree.chart.title.TextTitle)13