Search in sources :

Example 1 with DefaultPieDataset

use of org.jfree.data.general.DefaultPieDataset in project GT by Tencent.

the class PieChart method createChart.

private JFreeChart createChart() {
    this.dataset = new DefaultPieDataset();
    final JFreeChart chart = ChartFactory.createPieChart("内存构成分析", this.dataset, true, true, false);
    chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}"));
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 2 with DefaultPieDataset

use of org.jfree.data.general.DefaultPieDataset in project EnrichmentMapApp by BaderLab.

the class AbstractChartLayer method createPieDataset.

public static PieDataset createPieDataset(final List<Double> values) {
    final DefaultPieDataset dataset = new DefaultPieDataset();
    if (values != null) {
        for (int i = 0; i < values.size(); i++) {
            final Double v = values.get(i);
            final String k = "#" + (i + 1);
            dataset.setValue(k, v);
        }
    }
    return dataset;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) TexturePaint(java.awt.TexturePaint)

Example 3 with DefaultPieDataset

use of org.jfree.data.general.DefaultPieDataset in project cubrid-manager by CUBRID.

the class VolumeInformationEditor method createDataset.

/**
	 * create the dataset
	 *
	 * @return dataset
	 */
private DefaultPieDataset createDataset() {
    int freeSize, totalSize;
    freeSize = dbSpaceInfo.getFreepage();
    totalSize = dbSpaceInfo.getTotalpage();
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue(Messages.chartMsgUsedSize, (totalSize - freeSize) * (database.getDatabaseInfo().getDbSpaceInfoList().getPagesize() / (1048576.0f)));
    dataset.setValue(Messages.chartMsgFreeSize, (freeSize) * (database.getDatabaseInfo().getDbSpaceInfoList().getPagesize() / (1048576.0f)));
    return dataset;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset)

Example 4 with DefaultPieDataset

use of org.jfree.data.general.DefaultPieDataset in project adempiere by adempiere.

the class MChartDatasource method addData.

public void addData(MChart parent) {
    String value = getValueColumn();
    String category;
    String unit = "D";
    if (!parent.isTimeSeries())
        category = getCategoryColumn();
    else {
        if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Week)) {
            unit = "W";
        } else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Month)) {
            unit = "MM";
        } else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Quarter)) {
            unit = "Q";
        } else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Year)) {
            unit = "Y";
        }
        category = " TRUNC(" + getDateColumn() + ", '" + unit + "') ";
    }
    String series = DB.TO_STRING(getName());
    boolean hasSeries = false;
    if (getSeriesColumn() != null) {
        series = getSeriesColumn();
        hasSeries = true;
    }
    String where = getWhereClause();
    if (!Util.isEmpty(where)) {
        where = Env.parseContext(getCtx(), parent.getWindowNo(), where, true);
    }
    boolean hasWhere = false;
    String sql = "SELECT " + value + ", " + category + ", " + series + " FROM " + getFromClause();
    if (!Util.isEmpty(where)) {
        sql += " WHERE " + where;
        hasWhere = true;
    }
    Date currentDate = Env.getContextAsDate(getCtx(), "#Date");
    Date startDate = null;
    Date endDate = null;
    int scope = parent.getTimeScope();
    int offset = getTimeOffset();
    if (parent.isTimeSeries() && scope != 0) {
        offset += -scope;
        startDate = increment(currentDate, parent.getTimeUnit(), offset);
        endDate = increment(startDate, parent.getTimeUnit(), scope);
    }
    if (startDate != null && endDate != null) {
        sql += hasWhere ? " AND " : " WHERE ";
        sql += category + ">=TRUNC(" + DB.TO_DATE(new Timestamp(startDate.getTime())) + ", '" + unit + "') AND ";
        sql += category + "<=TRUNC(" + DB.TO_DATE(new Timestamp(endDate.getTime())) + ", '" + unit + "') ";
    }
    MRole role = MRole.getDefault(getCtx(), false);
    sql = role.addAccessSQL(sql, null, true, false);
    if (hasSeries)
        sql += " GROUP BY " + series + ", " + category + " ORDER BY " + series + ", " + category;
    else
        sql += " GROUP BY " + category + " ORDER BY " + category;
    log.log(Level.FINE, sql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    TimeSeries tseries = null;
    Dataset dataset = parent.getDataset();
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String key = rs.getString(2);
            String seriesName = rs.getString(3);
            if (seriesName == null)
                seriesName = getName();
            String queryWhere = "";
            if (hasWhere)
                queryWhere += where + " AND ";
            queryWhere += series + " = " + DB.TO_STRING(seriesName) + " AND " + category + " = ";
            if (parent.isTimeSeries() && dataset instanceof TimeSeriesCollection) {
                if (tseries == null || !tseries.getKey().equals(seriesName)) {
                    if (tseries != null)
                        ((TimeSeriesCollection) dataset).addSeries(tseries);
                    tseries = new TimeSeries(seriesName);
                }
                Date date = rs.getDate(2);
                RegularTimePeriod period = null;
                if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Day))
                    period = new Day(date);
                else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Week))
                    period = new Week(date);
                else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Month))
                    period = new Month(date);
                else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Quarter))
                    period = new Quarter(date);
                else if (parent.getTimeUnit().equals(MChart.TIMEUNIT_Year))
                    period = new Year(date);
                tseries.add(period, rs.getBigDecimal(1));
                key = period.toString();
                queryWhere += DB.TO_DATE(new Timestamp(date.getTime()));
            } else {
                queryWhere += DB.TO_STRING(key);
            }
            MQuery query = new MQuery(getAD_Table_ID());
            String keyCol = MTable.get(getCtx(), getAD_Table_ID()).getKeyColumns()[0];
            String whereClause = keyCol + " IN (SELECT " + getKeyColumn() + " FROM " + getFromClause() + " WHERE " + queryWhere + " )";
            query.addRestriction(whereClause.toString());
            query.setRecordCount(1);
            HashMap<String, MQuery> map = parent.getQueries();
            if (dataset instanceof DefaultPieDataset) {
                ((DefaultPieDataset) dataset).setValue(key, rs.getBigDecimal(1));
                map.put(key, query);
            } else if (dataset instanceof DefaultCategoryDataset) {
                ((DefaultCategoryDataset) dataset).addValue(rs.getBigDecimal(1), seriesName, key);
                map.put(seriesName + "__" + key, query);
            } else if (dataset instanceof TimeSeriesCollection) {
                map.put(seriesName + "__" + key, query);
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, sql);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (tseries != null)
        ((TimeSeriesCollection) dataset).addSeries(tseries);
}
Also used : Quarter(org.jfree.data.time.Quarter) DBException(org.adempiere.exceptions.DBException) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) TimeSeries(org.jfree.data.time.TimeSeries) SQLException(java.sql.SQLException) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Dataset(org.jfree.data.general.Dataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Date(java.util.Date) Month(org.jfree.data.time.Month) Year(org.jfree.data.time.Year) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ResultSet(java.sql.ResultSet) RegularTimePeriod(org.jfree.data.time.RegularTimePeriod) Day(org.jfree.data.time.Day) Week(org.jfree.data.time.Week) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 5 with DefaultPieDataset

use of org.jfree.data.general.DefaultPieDataset in project bamboobsc by billchen198318.

the class CommonPieChartAction method fillChart.

private void fillChart(String title, List<String> names, List<String> colors, List<Float> values) throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.setValue(names.get(ix), values.get(ix));
    }
    this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
    LegendTitle legend = this.chart.getLegend();
    legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
    PiePlot plot = (PiePlot) this.chart.getPlot();
    plot.setCircular(true);
    plot.setBackgroundAlpha(0.9f);
    plot.setForegroundAlpha(0.5f);
    plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) PiePlot(org.jfree.chart.plot.PiePlot) LegendTitle(org.jfree.chart.title.LegendTitle) Font(java.awt.Font)

Aggregations

DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)14 JFreeChart (org.jfree.chart.JFreeChart)4 PiePlot (org.jfree.chart.plot.PiePlot)4 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)3 Font (java.awt.Font)2 BigDecimal (java.math.BigDecimal)2 Account (jgnash.engine.Account)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 Color (java.awt.Color)1 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1