Example usage for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset

List of usage examples for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset DefaultCategoryDataset.

Prototype

public DefaultCategoryDataset() 

Source Link

Document

Creates a new (empty) dataset.

Usage

From source file:org.sakaiproject.evaluation.tool.reporting.EvalLikertChartBuilder.java

@SuppressWarnings("deprecation")
public JFreeChart makeLikertChart() {

    DefaultCategoryDataset likertDataset = new DefaultCategoryDataset();

    for (int i = 0; i < responses.length; i++) {
        likertDataset.addValue(values[i], "Responses", responses[i]);
    }/*from w w w.  j ava  2 s . c o m*/

    JFreeChart chart = ChartFactory.createBarChart(null, // "Likert Chart", // Chart title
            null, // "Choices", // domain axis label
            null, // "# of Responses", // range axis label
            likertDataset, PlotOrientation.HORIZONTAL, false, // show legend
            false, // show tooltips
            false // show URLs
    );

    // Set the background colours
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    // Configure the bar colors and display
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(244, 252, 212));
    renderer.setDrawBarOutline(true);
    renderer.setOutlinePaint(new Color(34, 35, 237));
    renderer.setOutlineStroke(new BasicStroke(0.5f));
    renderer.setBaseItemLabelsVisible(true);
    if (showPercentages) {
        renderer.setBaseItemLabelGenerator(new LikertPercentageItemLabelGenerator(this.responseCount));
    } else {
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    }
    // Turn off the Top Value Axis
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setVisible(false);
    rangeAxis.setUpperMargin(0.35);
    rangeAxis.resizeRange(1.1f);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setMaximumCategoryLabelWidthRatio(0.4f);
    domainAxis.setMaximumCategoryLabelLines(2);

    // Set the font for the labels
    Font labelFont = new Font("Serif", Font.PLAIN, 6);

    CategoryItemRenderer itemRenderer = plot.getRenderer();
    itemRenderer.setBaseItemLabelFont(labelFont);

    plot.setOutlinePaint(null);

    domainAxis.setLabelFont(labelFont);
    domainAxis.setTickLabelFont(labelFont);
    rangeAxis.setLabelFont(labelFont);
    rangeAxis.setTickLabelFont(labelFont);

    return chart;
}

From source file:Graphing.barGraph.java

private CategoryDataset getDataSet() {
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (int i = 0; i < this.category.length; i++) {
        dataSet.addValue(this.data[i], this.bargraph, this.category[i]);
    }/*from w  ww  .j  a  va 2  s .c  o m*/

    return dataSet;
}

From source file:filtros.histograma.Histograma.java

public static void Apply(BufferedImage image, String savePath) {
    //Chamada do metodo que gera os dados do histograma
    GetData(image);//from w w w .  jav a 2 s .  c  o  m

    //Dataset que gera o grafico
    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    //Loop que percorre o array de dados do histograma
    for (int k = 0; k < data.length; k++) {
        //Adiciona o valor ao dataset
        ds.setValue(data[k], "Imagem", Integer.toString(data[k]));
    }

    //Gera o grafico
    JFreeChart grafico = ChartFactory.createLineChart("Histograma", "Tons de cinza", "Valor", ds,
            PlotOrientation.VERTICAL, true, true, false);

    //Salva o grafico em um arquivo de png
    try {
        OutputStream arquivo = new FileOutputStream(savePath);
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400);
        arquivo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.opensourcestrategies.financials.reports.JFreeFinancialCharts.java

/**
 * Liquidity snapshot chart.  Documentation is at http://www.opentaps.org/docs/index.php/Financials_Home_Screen
 *
 * Because a user might not have permission to view balances in all areas, this method takes into consideration
 * the ability to view various bars in the chart.
 *
 * @param accountsMap Map of accounts keyed by the glAccountType
 * @return String filename pointing to the chart, to be used with showChart URI request
 *//* w  w  w.j  a  va2s  .c  o  m*/
public static String createLiquiditySnapshotChart(Map<String, GenericValue> accountsMap,
        List<GenericValue> creditCardAccounts, Locale locale, boolean hasReceivablesPermission,
        boolean hasPayablesPermission, boolean hasInventoryPermission)
        throws GenericEntityException, IOException {
    Map<String, Object> uiLabelMap = UtilMessage.getUiLabels(locale);

    // create the dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // compile the four bars
    if (hasReceivablesPermission) {
        double cashBalance = 0.0;
        cashBalance += getPostedBalance(accountsMap.get("UNDEPOSITED_RECEIPTS"));
        cashBalance += getPostedBalance(accountsMap.get("BANK_STLMNT_ACCOUNT"));
        dataset.addValue(cashBalance, "", (String) uiLabelMap.get("FinancialsCashEquivalents"));

        double receivablesBalance = 0.0;
        receivablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_RECEIVABLE"));
        // merchant account settlement balances are receivable
        receivablesBalance += getPostedBalance(accountsMap.get("MRCH_STLMNT_ACCOUNT"));
        dataset.addValue(receivablesBalance, "", (String) uiLabelMap.get("FinancialsReceivables"));
    }
    if (hasInventoryPermission) {
        double inventoryBalance = 0.0;
        inventoryBalance += getPostedBalance(accountsMap.get("INVENTORY_ACCOUNT"));
        inventoryBalance += getPostedBalance(accountsMap.get("RAWMAT_INVENTORY"));
        inventoryBalance += getPostedBalance(accountsMap.get("WIP_INVENTORY"));
        dataset.addValue(inventoryBalance, "", (String) uiLabelMap.get("WarehouseInventory"));
    }
    if (hasPayablesPermission) {
        double payablesBalance = 0.0;
        payablesBalance += getPostedBalance(accountsMap.get("ACCOUNTS_PAYABLE"));
        payablesBalance += getPostedBalance(accountsMap.get("COMMISSIONS_PAYABLE"));
        payablesBalance += getPostedBalance(accountsMap.get("UNINVOICED_SHIP_RCPT"));
        dataset.addValue(payablesBalance, "", (String) uiLabelMap.get("FinancialsPayables"));
    }

    // set up the chart
    JFreeChart chart = ChartFactory.createBarChart((String) uiLabelMap.get("FinancialsLiquiditySnapshot"), // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // get the bar renderer to put effects on the bars
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false); // disable bar outlines

    // set up gradient paint on bar
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.GREEN, 0.0f, 0.0f, Color.GRAY);
    renderer.setSeriesPaint(0, gp);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // tilt the category labels so they fit
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // save as a png and return the file name
    return ServletUtilities.saveChartAsPNG(chart, 400, 300, null);
}

From source file:org.fhaes.fhrecorder.view.ColorBarGraph.java

/**
 * Creates a data set for graphing./*from ww w .jav  a  2  s.c o m*/
 * 
 * @param years the data
 * @return the data set
 */
private static CategoryDataset createDataset(List<YearSummary> years) {

    CustomOptions options = FileController.getCustomOptions();
    DefaultCategoryDataset data = new DefaultCategoryDataset();

    for (YearSummary year : years)
        for (int i = 1; i <= 6; i++)
            data.addValue(compileData(options.getDataItems(i), year), options.getGroupName(i),
                    Integer.toString(year.getYear()));

    return new SlidingCategoryDataset(data, 0, FileController.MAX_VISIBLE_GRAPH_COLUMNS);
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.CategoryDataSetBasedChartBuilder.java

@Override
protected DatasetHolder newDatasetHolder() {
    return new DatasetHolder() {
        final private DefaultCategoryDataset _dataset = new DefaultCategoryDataset();

        @Override/*  ww  w . j  a v  a  2s. c  o m*/
        public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row) {
            String x = row.dimensionAsString(0);
            double y = row.dimensionAsDouble(1);
            _dataset.addValue(y, seriesDefinition.getSeriesLegend(), x);
        }

        @Override
        public void beginSeries(SeriesDefinition seriesDefinition) {
            // unused
        }

        @Override
        public void endSeries(SeriesDefinition seriesDefinition) {
            // unused
        }

        @Override
        public int getNumberOfDimensions() {
            return 2;
        }

        @Override
        public Dataset getPopulatedDataset() {
            return _dataset;
        }
    };
}

From source file:jasmine.imaging.core.JasmineCorrelationGraph.java

public void processData() {
    DefaultCategoryDataset series = new DefaultCategoryDataset();

    for (int i = 0; i < observed.length; i++) {
        StatisticsSolver obs = observed[i];
        double correlation = obs.getCorrelationWith(expected);
        if (!Double.isNaN(correlation)) {
            series.addValue(correlation, "series1", names[i]);
        }//w  ww  .  ja v a 2  s .com
        System.out.println(names[i] + ": " + correlation);
    }

    myChart = ChartFactory.createBarChart(null, "Features", "Pearson Correlation", series,
            PlotOrientation.VERTICAL, false, false, false);

}

From source file:com.googlecode.logVisualizer.chart.SkillCastsBarChart.java

@Override
protected CategoryDataset createDataset() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String seriesName = "Skills cast";

    // Add skills to the dataset. The list is sorted from most amount of
    // casts to least amount of casts.
    for (final Skill s : getLogData().getAllSkillsCast()) {
        dataset.addValue(s.getAmount(), seriesName, s.getName());

        // The chart isn't readable anymore with too many entries
        if (dataset.getColumnCount() > 45)
            break;
    }/* ww  w  . java 2 s .  c o m*/

    return dataset;
}

From source file:room.utilization.BarGraph.java

private CategoryDataset createDataset() {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    int len = 0;/*from w  w  w . ja va2s  . c  o m*/

    for (int x = 0; x < data.length; x++) {
        len = data[x].length;
        ds.addValue(Double.parseDouble(data[x][len - 1]), data[x][0], data[x][0]);
    }

    return ds;
}

From source file:com.googlecode.logVisualizer.chart.TurnsSpentPerAreaBarChart.java

@Override
protected CategoryDataset createDataset() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String seriesName = "Turns spent per area";

    // Add areas to the dataset. They are sorted from most visited to least
    // visited.//  www  .  j  a va 2 s . c om
    for (final DataNumberPair<String> dn : getLogData().getLogSummary().getTurnsPerArea()) {
        dataset.addValue(dn.getNumber(), seriesName, dn.getData());

        // The chart isn't readable anymore with too many entries
        if (dataset.getColumnCount() > 45)
            break;
    }

    return dataset;
}