Example usage for org.jfree.chart.title LegendTitle setSortOrder

List of usage examples for org.jfree.chart.title LegendTitle setSortOrder

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setSortOrder.

Prototype

public void setSortOrder(SortOrder order) 

Source Link

Document

Sets the order used to display legend items.

Usage

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TimeChartDataSet addTimeSeries(TimeChartDataSet dataset) throws InvalidArgument {
    if (dataset == null) {
        dataset = makeDataSet(1);/*  w w w  .j a  v  a  2s . c  om*/
    }

    if (chart == null) {
        chart = ChartFactory.createTimeSeriesChart(title, "Time", quantity, dataset, true, false, false);
        XYPlot xyPlot = (XYPlot) chart.getPlot();

        DateAxis axis = (DateAxis) xyPlot.getDomainAxis();
        //axis.setRange(period.getStart(), period.getEnd());
        //axis.setLowerMargin(0.0);
        //axis.setUpperMargin(0.0);

        if (period instanceof CalendarFieldSplitPeriod) {
            TickUnits u = getUnits((CalendarFieldSplitPeriod) period);
            if (u != null) {
                axis.setStandardTickUnits(u);
            }
        }
        axis.setMinimumDate(period.getStart());
        axis.setMaximumDate(period.getEnd());
        LegendTitle leg = chart.getLegend();
        leg.setSortOrder(SortOrder.DESCENDING);
        leg.setPosition(RectangleEdge.RIGHT);
    } else {
        XYPlot xyPlot = (XYPlot) chart.getPlot();
        xyPlot.setDataset(ndatasets, dataset);
    }
    dataset.setDatasetId(ndatasets);
    ndatasets++;
    plots.add(dataset);
    return dataset;
}