Example usage for org.jfree.util SortOrder DESCENDING

List of usage examples for org.jfree.util SortOrder DESCENDING

Introduction

In this page you can find the example usage for org.jfree.util SortOrder DESCENDING.

Prototype

SortOrder DESCENDING

To view the source code for org.jfree.util SortOrder DESCENDING.

Click Source Link

Document

Descending order.

Usage

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
* Creates a stacked bar chart with a 3D effect and default settings. The     
* chart object returned by this method uses a {@link CategoryPlot}     
* instance as the plot, with a {@link CategoryAxis3D} for the domain axis,     
* a {@link NumberAxis3D} as the range axis, and a     
* {@link StackedBarRenderer3D} as the renderer.    
*    /*from w w  w.  jav a 2 s . c  om*/
* @param title  the chart title (<code>null</code> permitted).    
* @param categoryAxisLabel  the label for the category axis     
*                           (<code>null</code> permitted).    
* @param valueAxisLabel  the label for the value axis (<code>null</code>     
*                        permitted).    
* @param dataset  the dataset for the chart (<code>null</code> permitted).    
* @param orientation  the orientation (horizontal or vertical)     
*                     (<code>null</code> not permitted).    
* @param legend  a flag specifying whether or not a legend is required.    
* @param tooltips  configure chart to generate tool tips?    
* @param urls  configure chart to generate URLs?    
*    
* @return A stacked bar chart with a 3D effect.    
*/
public static JFreeChart createStackedBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    // create the renderer...    
    CategoryItemRenderer renderer = new StackedBarRenderer3D();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    // create the plot...    
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        // change rendering order to ensure that bar overlapping is the     
        // right way around    
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }

    // create the chart...    
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates a stacked bar chart with a 3D effect and default settings. The
 * chart object returned by this method uses a {@link CategoryPlot}
 * instance as the plot, with a {@link CategoryAxis3D} for the domain axis,
 * a {@link NumberAxis3D} as the range axis, and a
 * {@link StackedBarRenderer3D} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param valueAxisLabel  the label for the value axis (<code>null</code>
 *                        permitted)./*from w w w .  jav  a2 s . co m*/
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the orientation (horizontal or vertical)
 *                     (<code>null</code> not permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A stacked bar chart with a 3D effect.
 */
public static JFreeChart createStackedBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);

    // create the renderer...
    CategoryItemRenderer renderer = new StackedBarRenderer3D();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    }

    // create the plot...
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        // change rendering order to ensure that bar overlapping is the
        // right way around
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }

    // create the chart...
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private AbstractDataset getPieDataset(Report report) {
    List<Stat> reportData = report.getReportData();

    // fill dataset
    DefaultPieDataset dataSet = new DefaultPieDataset();
    String dataSource = report.getReportDefinition().getReportParams().getHowChartSource();
    //int total = 0;
    double total = 0;
    for (Stat s : reportData) {
        Comparable key = getStatValue(s, dataSource);
        if (key != null) {
            try {
                Number existingValue = dataSet.getValue(key);
                dataSet.setValue(key, getTotalValue(existingValue, s, report));
                total += getTotalValue(s, report).doubleValue();
            } catch (UnknownKeyException e) {
                dataSet.setValue(key, getTotalValue(s, report));
                total += getTotalValue(s, report).doubleValue();
            }/*from w ww . java 2s  . c  o m*/
        }
    }

    // sort
    dataSet.sortByValues(SortOrder.DESCENDING);

    // fill in final key values in dataset
    // show only top values (aggregate remaining in 'others')
    int maxDisplayedItems = 10;
    int currItem = 1;
    Number othersValues = Integer.valueOf(0);
    List<Comparable> keys = dataSet.getKeys();
    for (Comparable key : keys) {
        Number existingValue = dataSet.getValue(key);
        if (currItem < maxDisplayedItems) {
            // re-compute values
            double percentage = (double) existingValue.doubleValue() * 100 / total;
            double valuePercentage = Util.round(percentage, (percentage > 0.1) ? 1 : 2);
            // replace key with updated label
            StringBuilder keyStr = new StringBuilder(key.toString());
            keyStr.append(' ');
            keyStr.append(valuePercentage);
            keyStr.append("% (");
            if ((double) existingValue.intValue() == existingValue.doubleValue())
                keyStr.append(existingValue.intValue());
            else
                keyStr.append(existingValue.doubleValue());
            keyStr.append(")");
            dataSet.remove(key);
            dataSet.setValue(keyStr.toString(), existingValue);
        } else {
            othersValues = Integer.valueOf(othersValues.intValue() + existingValue.intValue());
            dataSet.remove(key);
        }
        currItem++;
    }
    // compute "Others" value
    if (othersValues.intValue() > 0) {
        double percentage = (double) othersValues.doubleValue() * 100 / total;
        double valuePercentage = Util.round(percentage, (percentage > 0.1) ? 1 : 2);
        // replace key with updated label
        StringBuilder keyStr = new StringBuilder(msgs.getString("pie_chart_others"));
        keyStr.append(' ');
        keyStr.append(valuePercentage);
        keyStr.append("% (");
        if ((double) othersValues.intValue() == othersValues.doubleValue())
            keyStr.append(othersValues.intValue());
        else
            keyStr.append(othersValues.doubleValue());
        keyStr.append(")");
        dataSet.setValue(keyStr.toString(), othersValues);
    }

    return dataSet;
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] generateLayeredBarChart(CategoryDataset dataset, int width, int height) {
    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );//w  w  w  . j  a v  a 2 s  .  com

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // disable bar outlines...
    LayeredBarRenderer renderer = new LayeredBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setSeriesBarWidth(0, .6);
    renderer.setSeriesBarWidth(1, .8);
    renderer.setSeriesBarWidth(2, 1.0);
    plot.setRenderer(renderer);

    // for this renderer, we need to draw the first series last...
    plot.setRowRenderingOrder(SortOrder.DESCENDING);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createCategoryBarChart(String title, String xLabel, String yLabel, CategoryDataset dataset) {

    //  System.out.println("layout = "+layout);
    JFreeChart chart;/*from  w w  w  . j  a  va  2  s . c o m*/
    if (dimension.equalsIgnoreCase("3d")) {

        chart = ChartFactory.createBarChart3D(title, // chart title
                xLabel, // domain axis label
                yLabel, // range axis label
                dataset, // data
                orientation, // orientation
                true, // include legend
                true, // tooltips
                false // urls
        );
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinesVisible(true);
        CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));
        BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
        //renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
        renderer.setDrawBarOutline(false);
        return chart;
    }
    if (layout.equalsIgnoreCase("stacked")) {
        chart = ChartFactory.createStackedBarChart(title, // chart title
                xLabel, // domain axis label
                yLabel, // range axis label
                dataset, // data
                orientation, // the plot orientation
                true, // legend
                true, // tooltips
                false // urls
        );
    } else if (layout.equalsIgnoreCase("waterfall")) {
        chart = ChartFactory.createWaterfallChart(title, xLabel, yLabel, dataset, orientation, true, true,
                false);
        CategoryPlot plot = chart.getCategoryPlot();
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);

        DecimalFormat labelFormatter = new DecimalFormat("$##,###.00");
        labelFormatter.setNegativePrefix("(");
        labelFormatter.setNegativeSuffix(")");
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter));
        renderer.setBaseItemLabelsVisible(true);
    } else {
        chart = ChartFactory.createBarChart(title, // chart title
                xLabel, // domain axis label
                yLabel, // range axis label
                dataset, // data
                orientation, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );
    }

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    if (layout.equalsIgnoreCase("stacked")) {
        StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        renderer.setBaseItemLabelsVisible(true);
        renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    } else if (layout.equalsIgnoreCase("layered")) {
        LayeredBarRenderer renderer = new LayeredBarRenderer();
        renderer.setDrawBarOutline(false);
        plot.setRenderer(renderer);
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
    } else {
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
    }

    /*   CategoryAxis domainAxis = plot.getDomainAxis();
     domainAxis.setCategoryLabelPositions(
         CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
     );*/
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}