Search in sources :

Example 1 with CategoryDataset

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

the class VCRP method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        Timestamp date = null;
        if (dateFrom.getValue() != null)
            date = (Timestamp) dateFrom.getValue();
        int S_Resource_ID = 0;
        if (resource.getValue() != null)
            S_Resource_ID = ((Integer) resource.getValue()).intValue();
        if (date != null && S_Resource_ID != 0) {
            MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
            int uom_id = r.getResourceType().getC_UOM_ID();
            MUOM uom = MUOM.get(Env.getCtx(), uom_id);
            CategoryDataset dataset = null;
            if (uom.isHour()) {
                dataset = createDataset(date, r);
            } else {
                dataset = createWeightDataset(date, r);
            }
            String title = r.getName() != null ? r.getName() : "";
            title = title + " " + r.getDescription() != null ? r.getDescription() : "";
            JFreeChart jfreechart = createChart(dataset, title, uom);
            centerPanel.removeAll();
            chartPanel = new ChartPanel(jfreechart, false);
            centerPanel.add(chartPanel, BorderLayout.CENTER);
            centerPanel.setVisible(true);
            m_frame.pack();
        }
    }
    if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) ChartPanel(org.jfree.chart.ChartPanel) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Timestamp(java.sql.Timestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with CategoryDataset

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

the class WCRP method onEvent.

@Override
public void onEvent(Event event) throws Exception {
    String cmd = event.getTarget().getId();
    if (cmd.equals(ConfirmPanel.A_OK)) {
        Timestamp date = null;
        if (dateFrom.getValue() != null)
            date = (Timestamp) dateFrom.getValue();
        int S_Resource_ID = 0;
        if (resource.getValue() != null)
            S_Resource_ID = ((Integer) resource.getValue()).intValue();
        if (date != null && S_Resource_ID != 0) {
            MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
            int uom_id = r.getResourceType().getC_UOM_ID();
            MUOM uom = MUOM.get(Env.getCtx(), uom_id);
            CategoryDataset dataset = null;
            if (uom.isHour()) {
                dataset = createDataset(date, r);
            } else {
                dataset = createWeightDataset(date, r);
            }
            String title = r.getName() != null ? r.getName() : "";
            title = title + " " + r.getDescription() != null ? r.getDescription() : "";
            JFreeChart jfreechart = createChart(dataset, title, uom);
            renderChart(jfreechart);
        }
    }
    if (cmd.equals(ConfirmPanel.A_CANCEL)) {
        dispose();
    }
}
Also used : MResource(org.compiere.model.MResource) MUOM(org.compiere.model.MUOM) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Timestamp(java.sql.Timestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 3 with CategoryDataset

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

the class DefaultChartService method getJFreeChart.

/**
     * Returns a JFreeChart of type defined in the chart argument.
     */
private JFreeChart getJFreeChart(BaseChart chart) {
    final CategoryDataset[] dataSets = getCategoryDataSet(chart);
    final CategoryDataset dataSet = dataSets[0];
    final BarRenderer barRenderer = getBarRenderer();
    final LineAndShapeRenderer lineRenderer = getLineRenderer();
    // ---------------------------------------------------------------------
    // Plot
    // ---------------------------------------------------------------------
    CategoryPlot plot = null;
    if (chart.isType(ChartType.LINE)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.COLUMN)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.BAR)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    } else if (chart.isType(ChartType.AREA)) {
        return getStackedAreaChart(chart, dataSet);
    } else if (chart.isType(ChartType.PIE)) {
        return getMultiplePieChart(chart, dataSets);
    } else if (chart.isType(ChartType.STACKED_COLUMN)) {
        return getStackedBarChart(chart, dataSet, false);
    } else if (chart.isType(ChartType.STACKED_BAR)) {
        return getStackedBarChart(chart, dataSet, true);
    } else if (chart.isType(ChartType.RADAR)) {
        return getRadarChart(chart, dataSet);
    } else if (chart.isType(ChartType.GAUGE)) {
        Number number = dataSet.getValue(0, 0);
        ValueDataset valueDataSet = new DefaultValueDataset(number);
        return getGaugeChart(chart, valueDataSet);
    } else {
        throw new IllegalArgumentException("Illegal or no chart type: " + chart.getType());
    }
    if (chart.isRegression()) {
        plot.setDataset(1, dataSets[1]);
        plot.setRenderer(1, lineRenderer);
    }
    JFreeChart jFreeChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
    setBasicConfig(jFreeChart, chart);
    if (chart.isTargetLine()) {
        plot.addRangeMarker(getMarker(chart.getTargetLineValue(), chart.getTargetLineLabel()));
    }
    if (chart.isBaseLine()) {
        plot.addRangeMarker(getMarker(chart.getBaseLineValue(), chart.getBaseLineLabel()));
    }
    if (chart.isHideSubtitle()) {
        jFreeChart.addSubtitle(getSubTitle(chart));
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // ---------------------------------------------------------------------
    // Category label positions
    // ---------------------------------------------------------------------
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLabel(chart.getDomainAxisLabel());
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabel(chart.getRangeAxisLabel());
    return jFreeChart;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 4 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project processdash by dtuma.

the class DiscChart method createDiscChart.

public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
    // data.sortBy(1, true);
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    DiscPlot plot = new DiscPlot(pieData);
    plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
    plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("discLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        ((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);
    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }
    return chart;
}
Also used : DiscPlot(net.sourceforge.processdash.ui.lib.chart.DiscPlot) PieDataset(org.jfree.data.general.PieDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart)

Example 5 with CategoryDataset

use of org.jfree.data.category.CategoryDataset in project processdash by dtuma.

the class PieChart method createChart.

/** Create a  line chart. */
@Override
public JFreeChart createChart() {
    CategoryDataset catData = data.catDataSource();
    PieDataset pieData = null;
    if (catData.getColumnCount() == 1)
        pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
    else
        pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
    JFreeChart chart = null;
    if (get3DSetting()) {
        chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
        chart.getPlot().setForegroundAlpha(ALPHA);
    } else {
        chart = ChartFactory.createPieChart(null, pieData, true, true, false);
    }
    PiePlot plot = (PiePlot) chart.getPlot();
    if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
        plot.setLabelGenerator(null);
    else if (parameters.get("wedgeLabelFontSize") != null)
        try {
            float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
            plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
        } catch (Exception lfe) {
        }
    if (parameters.get("ellipse") != null)
        plot.setCircular(true);
    else
        plot.setCircular(false);
    Object colorScheme = parameters.get("colorScheme");
    if ("byPhase".equals(colorScheme))
        maybeConfigurePhaseColors(plot, pieData);
    else if ("consistent".equals(colorScheme))
        // since 2.0.9
        configureConsistentColors(plot, pieData);
    else if (parameters.containsKey("c1"))
        configureIndividualColors(plot, pieData);
    String interiorGap = (String) parameters.get("interiorGap");
    if (interiorGap != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
        } catch (NumberFormatException e) {
        }
    String interiorSpacing = (String) parameters.get("interiorSpacing");
    if (interiorSpacing != null)
        try {
            plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
        } catch (NumberFormatException e) {
        }
    if (!parameters.containsKey("showZeroValues")) {
        plot.setIgnoreZeroValues(true);
        plot.setIgnoreNullValues(true);
    }
    return chart;
}
Also used : PieDataset(org.jfree.data.general.PieDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) PiePlot(org.jfree.chart.plot.PiePlot) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

CategoryDataset (org.jfree.data.category.CategoryDataset)34 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)18 JFreeChart (org.jfree.chart.JFreeChart)15 CategoryPlot (org.jfree.chart.plot.CategoryPlot)12 CategoryAxis (org.jfree.chart.axis.CategoryAxis)9 NumberAxis (org.jfree.chart.axis.NumberAxis)7 ValueAxis (org.jfree.chart.axis.ValueAxis)6 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)4 PieDataset (org.jfree.data.general.PieDataset)4 BoxAndWhiskerCategoryDataset (org.jfree.data.statistics.BoxAndWhiskerCategoryDataset)4 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)4 RectangleInsets (org.jfree.ui.RectangleInsets)4 Paint (java.awt.Paint)3 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)3 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)2 StackedAreaRenderer2 (hudson.util.StackedAreaRenderer2)2 Timestamp (java.sql.Timestamp)2 DecimalFormat (java.text.DecimalFormat)2 ArrayList (java.util.ArrayList)2 SimpleRegression (org.apache.commons.math3.stat.regression.SimpleRegression)2