Search in sources :

Example 21 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.

the class GraphBuilder method loadData.

/**
	 *
	 * @return graph column list
	 */
public ArrayList<GraphColumn> loadData() {
    //	Calculated
    MMeasure measure = getMGoal().getMeasure();
    if (measure == null) {
        log.warning("No Measure for " + getMGoal());
        return null;
    }
    ArrayList<GraphColumn> list = measure.getGraphColumnList(getMGoal());
    pieDataset = new DefaultPieDataset();
    dataset = new DefaultCategoryDataset();
    for (int i = 0; i < list.size(); i++) {
        String series = m_X_AxisLabel;
        if (list.get(i).getDate() != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(list.get(i).getDate());
            series = Integer.toString(cal.get(Calendar.YEAR));
        }
        dataset.addValue(list.get(i).getValue(), series, list.get(i).getLabel());
        linearDataset.addValue(list.get(i).getValue(), m_X_AxisLabel, list.get(i).getLabel());
        pieDataset.setValue(list.get(i).getLabel(), list.get(i).getValue());
    }
    return list;
}
Also used : MMeasure(org.compiere.model.MMeasure) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) Calendar(java.util.Calendar) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 22 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.

the class WCRP method jbInit.

private void jbInit() throws Exception {
    resourceLabel.setText(Msg.translate(Env.getCtx(), "S_Resource_ID"));
    dateFromLabel.setText(Msg.translate(Env.getCtx(), "DateFrom"));
    Rows rows = new Rows();
    Row row = null;
    rows.setParent(northPanel);
    row = rows.newRow();
    row.appendChild(resourceLabel.rightAlign());
    row.appendChild(resource.getComponent());
    row.appendChild(dateFromLabel.rightAlign());
    row.appendChild(dateFrom.getComponent());
    centerPanel.appendChild(chartPanel);
    JFreeChart jchart = ChartFactory.createBarChart3D("", // X-Axis label
    Msg.translate(Env.getCtx(), "Days"), // Y-Axis label
    Msg.translate(Env.getCtx(), "Hours"), // Dataset
    new DefaultCategoryDataset(), // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips?
    true, // URLs?
    false);
    renderChart(jchart);
    confirmPanel.addActionListener(this);
}
Also used : Row(org.zkoss.zul.Row) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) Rows(org.adempiere.webui.component.Rows)

Example 23 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project bamboobsc by billchen198318.

the class CommonBarChartAction method fillChart.

private void fillChart(String title, String categoryLabel, String valueLabel, List<String> names, List<Float> values, List<String> colors, boolean horizontal) throws Exception {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.addValue(values.get(ix), "", names.get(ix));
    }
    this.chart = ChartFactory.createBarChart3D(// title
    title, categoryLabel, valueLabel, data, (horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL), false, false, false);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.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) NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Font(java.awt.Font)

Example 24 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project dhis2-core by dhis2.

the class DefaultChartService method getCategoryDataSet.

private CategoryDataset[] getCategoryDataSet(BaseChart chart) {
    Map<String, Object> valueMap = new HashMap<>();
    if (chart.isAnalyticsType(AnalyticsType.AGGREGATE)) {
        valueMap = analyticsService.getAggregatedDataValueMapping(chart);
    } else if (chart.isAnalyticsType(AnalyticsType.EVENT)) {
        Grid grid = eventAnalyticsService.getAggregatedEventData(chart);
        chart.setDataItemGrid(grid);
        valueMap = GridUtils.getMetaValueMapping(grid, (grid.getWidth() - 1));
    }
    DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
    DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
    SimpleRegression regression = new SimpleRegression();
    BaseAnalyticalObject.sortKeys(valueMap);
    List<NameableObject> seriez = new ArrayList<>(chart.series());
    List<NameableObject> categories = new ArrayList<>(chart.category());
    if (chart.hasSortOrder()) {
        categories = getSortedCategories(categories, chart, valueMap);
    }
    for (NameableObject series : seriez) {
        double categoryIndex = 0;
        for (NameableObject category : categories) {
            categoryIndex++;
            String key = getKey(series, category, chart.getAnalyticsType());
            Object object = valueMap.get(key);
            Number value = object != null && object instanceof Number ? (Number) object : null;
            regularDataSet.addValue(value, series.getShortName(), category.getShortName());
            if (chart.isRegression() && value != null && value instanceof Double && !MathUtils.isEqual((Double) value, MathUtils.ZERO)) {
                regression.addData(categoryIndex, (Double) value);
            }
        }
        if (// Period must be category
        chart.isRegression()) {
            categoryIndex = 0;
            for (NameableObject category : chart.category()) {
                final double value = regression.predict(categoryIndex++);
                if (!Double.isNaN(value)) {
                    regressionDataSet.addValue(value, TREND_PREFIX + series.getShortName(), category.getShortName());
                }
            }
        }
    }
    return new CategoryDataset[] { regularDataSet, regressionDataSet };
}
Also used : SimpleRegression(org.apache.commons.math3.stat.regression.SimpleRegression) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 25 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project dhis2-core by dhis2.

the class DefaultChartService method getJFreeChart.

@Override
public JFreeChart getJFreeChart(String name, PlotOrientation orientation, CategoryLabelPositions labelPositions, Map<String, Double> categoryValues) {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    for (Entry<String, Double> entry : categoryValues.entrySet()) {
        dataSet.addValue(entry.getValue(), name, entry.getKey());
    }
    CategoryPlot plot = getCategoryPlot(dataSet, getBarRenderer(), orientation, labelPositions);
    JFreeChart jFreeChart = getBasicJFreeChart(plot);
    jFreeChart.setTitle(name);
    return jFreeChart;
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)26 JFreeChart (org.jfree.chart.JFreeChart)9 CategoryPlot (org.jfree.chart.plot.CategoryPlot)7 Paint (java.awt.Paint)6 NumberAxis (org.jfree.chart.axis.NumberAxis)5 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)4 StandardBarPainter (org.jfree.chart.renderer.category.StandardBarPainter)4 Color (java.awt.Color)3 Timestamp (java.sql.Timestamp)3 Mongo (com.mongodb.Mongo)2 Font (java.awt.Font)2 ArrayList (java.util.ArrayList)2 GregorianCalendar (java.util.GregorianCalendar)2 ColorScheme (org.baderlab.csplugins.enrichmentmap.style.ColorScheme)2 MResourceType (org.compiere.model.MResourceType)2 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)2 TextTitle (org.jfree.chart.title.TextTitle)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 RectangleInsets (org.jfree.ui.RectangleInsets)2