Search in sources :

Example 6 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project opennms by OpenNMS.

the class ChartUtils method getBarChart.

/**
     * This method will returns a JFreeChart bar chart constructed based on XML configuration.
     *
     * @param chartName Name specified in chart-configuration.xml
     * @return <code>JFreeChart</code> constructed from the chartName
     * @throws java.io.IOException if any.
     * @throws java.sql.SQLException if any.
     */
public static JFreeChart getBarChart(String chartName) throws IOException, SQLException {
    //ChartConfigFactory.reload();
    BarChart chartConfig = null;
    chartConfig = getBarChartConfigByName(chartName);
    if (chartConfig == null) {
        throw new IllegalArgumentException("getBarChart: Invalid chart name.");
    }
    DefaultCategoryDataset baseDataSet = buildCategoryDataSet(chartConfig);
    JFreeChart barChart = createBarChart(chartConfig, baseDataSet);
    addSubTitles(chartConfig, barChart);
    if (chartConfig.getSubLabelClass().isPresent()) {
        addSubLabels(barChart, chartConfig.getSubLabelClass().get());
    }
    customizeSeries(barChart, chartConfig);
    return barChart;
}
Also used : BarChart(org.opennms.netmgt.config.charts.BarChart) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 7 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatStripsLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int total = dataSets.size();
    int v = total / -2;
    for (int i = 0; i < total; i++) {
        // Just to make sure there is always a bar for each data set name
        if (v == 0.0)
            v = 1;
        dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
    }
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(true);
    domainAxis.setAxisLineVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setMaximumCategoryLabelLines(1);
    domainAxis.setCategoryMargin(0.0);
    if (total > 4) {
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
        domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
    } else {
        domainAxis.setMaximumCategoryLabelLines(2);
    }
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    List<Color> itemColors = new ArrayList<>();
    for (int i = 0; i < total; i++) {
        Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
        itemColors.add(ColorUtil.getColor(n.doubleValue(), -total, total, colors.get(2), colors.get(1), colors.get(0)));
    }
    final BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(int row, int column) {
            return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
        }
    };
    plot.setRenderer(renderer);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(0.0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ArrayList(java.util.ArrayList) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) Paint(java.awt.Paint) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 8 with DefaultCategoryDataset

use of org.jfree.data.category.DefaultCategoryDataset in project EnrichmentMapApp by BaderLab.

the class AbstractChartLayer method createCategoryDataset.

public static CategoryDataset createCategoryDataset(final Map<String, List<Double>> data, final boolean listIsSeries, List<String> labels) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (listIsSeries && (labels == null || labels.isEmpty())) {
        int size = 0;
        for (final List<Double> values : data.values()) size = Math.max(size, values.size());
        labels = createDefaultLabels(size);
    }
    int count = 0;
    for (String category : data.keySet()) {
        final List<Double> values = data.get(category);
        for (int i = 0; i < values.size(); i++) {
            final Double v = values.get(i);
            // row key
            String k = "#" + (i + 1);
            if (listIsSeries) {
                if (labels != null && labels.size() > i)
                    k = labels.get(i);
                dataset.addValue(v, category, k);
            } else {
                if (labels != null && labels.size() > count)
                    // Use label for category name
                    category = labels.get(count);
                dataset.addValue(v, k, category);
            }
        }
        count++;
    }
    return dataset;
}
Also used : DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) TexturePaint(java.awt.TexturePaint)

Example 9 with DefaultCategoryDataset

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

the class CRPDatasetFactory method generate.

private void generate(Timestamp start, Timestamp end, MResource r) {
    if (start == null || end == null || r == null) {
        return;
    }
    String labelActCap = Msg.translate(Env.getCtx(), "DailyCapacity");
    String labelLoadAct = Msg.translate(Env.getCtx(), "ActualLoad");
    DateFormat formatter = DisplayType.getDateFormat(DisplayType.DateTime, Env.getLanguage(Env.getCtx()));
    BigDecimal dailyCapacity = getMaxRange(r);
    dataset = new DefaultCategoryDataset();
    HashMap<DefaultMutableTreeNode, String> names = new HashMap<DefaultMutableTreeNode, String>();
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(r);
    names.put(root, getTreeNodeRepresentation(null, root, r));
    Timestamp dateTime = start;
    while (end.after(dateTime)) {
        String label = formatter.format(dateTime);
        names.putAll(addTreeNodes(dateTime, root, r));
        boolean available = isAvailable(r, dateTime);
        dataset.addValue(available ? dailyCapacity : BigDecimal.ZERO, labelActCap, label);
        dataset.addValue(available ? calculateLoad(dateTime, r, null) : BigDecimal.ZERO, labelLoadAct, label);
        // TODO: teo_sarca: increment should be more general, not only days
        dateTime = org.compiere.util.TimeUtil.addDays(dateTime, 1);
    }
    tree = new JTree(root);
    tree.setCellRenderer(new DiagramTreeCellRenderer(names));
}
Also used : JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 10 with DefaultCategoryDataset

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

the class CRP method createDataset.

/**
     * Create Category Dataset based on date start and resource
     * @param start
     * @param resource
     * @return CategoryDataset
     */
protected CategoryDataset createDataset(Timestamp start, MResource resource) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);
    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID());
    int days = 1;
    long hours = t.getTimeSlotHours();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    //		Long Hours = new Long(hours); 			 		 			 
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID());
    MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID);
    if (!uom.isHour()) {
        return dataset;
    }
    long summary = 0;
    while (days < 32) {
        String day = new String(new Integer(date.getDate()).toString());
        long HoursLoad = getLoad(resource, date).longValue();
        Long Hours = new Long(hours);
        switch(gc1.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.SUNDAY:
                days++;
                if (t.isOnSunday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.MONDAY:
                days++;
                if (t.isOnMonday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.TUESDAY:
                days++;
                if (t.isOnTuesday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.WEDNESDAY:
                days++;
                if (t.isOnWednesday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.THURSDAY:
                days++;
                if (t.isOnThursday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.FRIDAY:
                days++;
                if (t.isOnFriday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
            case Calendar.SATURDAY:
                days++;
                if (t.isOnSaturday()) {
                    dataset.addValue(hours, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary + Hours.intValue() - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                } else {
                    dataset.addValue(0, namecapacity, day);
                    dataset.addValue(HoursLoad, nameload, day);
                    dataset.addValue(summary, namesummary, day);
                    summary = summary - (HoursLoad);
                    gc1.add(Calendar.DATE, 1);
                    date = new Timestamp(gc1.getTimeInMillis());
                    break;
                }
        }
    }
    return dataset;
}
Also used : MUOM(org.compiere.model.MUOM) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) MResourceType(org.compiere.model.MResourceType)

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