Example usage for org.jfree.chart.axis NumberAxis NumberAxis

List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis NumberAxis.

Prototype

public NumberAxis(String label) 

Source Link

Document

Constructs a number axis, using default values where necessary.

Usage

From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java

/**
 * Creates a chart.//  ww w  . j a v a 2s.  co m
 * 
 * @return A chart.
 */
private JFreeChart createChart(String title) {

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[subplotCount];

    for (int i = 0; i < subplotCount; i++) {
        this.lastValue[i] = 100.0;
        final TimeSeries series = new TimeSeries("Real Time", Millisecond.class);
        this.datasets[i] = new TimeSeriesCollection(series);
        final NumberAxis rangeAxis = new NumberAxis("Schedule");
        rangeAxis.setAutoRangeIncludesZero(false);
        final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new XYLineAndShapeRenderer());

        subplot.setBackgroundPaint(Color.white);
        subplot.setDomainGridlinePaint(Color.lightGray);
        subplot.setRangeGridlinePaint(Color.lightGray);
        plot.add(subplot);
    }

    final JFreeChart chart = new JFreeChart(title, plot);

    chart.removeLegend();
    // chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);

    Paint p = GanttPlotter.getBackgroundColorGradient();
    chart.setBackgroundPaint(p);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);

    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);

    return chart;

}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo.java

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {
    //DomainAxis/*from   w  ww.  ja  v a 2  s .  co  m*/
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setAutoRange(false);
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    XYURLGenerator urlGenerator = null;
    //            urlGenerator = new StandardXYURLGenerator();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    //Plot
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:com.unicornlabs.kabouter.gui.power.PowerPanel.java

/**
 * Sets the chart data and title/*from w  ww.  j  a  v  a 2s.  co  m*/
 *
 * @param logs the list of power logs
 * @param title the title of the chart
 */
public void setupChart(ArrayList<Powerlog> logs, String title) {

    myDataSeriesMap.clear();

    //Create a collection to store the series
    dataset = new XYSeriesCollection();

    //Add each of the logs to the series
    for (Powerlog p : logs) {
        XYSeries deviceSeries = myDataSeriesMap.get(p.getId().getDeviceid());

        if (deviceSeries == null) {
            deviceSeries = new XYSeries(p.getId().getDeviceid());
            myDataSeriesMap.put(p.getId().getDeviceid(), deviceSeries);
            dataset.addSeries(deviceSeries);
        }

        deviceSeries.add(p.getId().getLogtime().getTime(), p.getPower());
    }

    //Create a custom date axis to display dates on the X axis
    DateAxis dateAxis = new DateAxis("Date");
    //Make the labels vertical
    dateAxis.setVerticalTickLabels(true);

    //Create the power axis
    NumberAxis powerAxis = new NumberAxis("Power");

    //Set both axes to auto range for their values
    powerAxis.setAutoRange(true);
    dateAxis.setAutoRange(true);

    //Create the tooltip generator
    StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
            new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

    //Set the renderer
    StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null);

    //Create the plot
    XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

    //Create the chart
    myChart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //Attach the chart to the panel
    ((ChartPanel) chartPanel).setChart(myChart);
    //Set max draw size to 2560x1440
    ((ChartPanel) chartPanel).setMaximumDrawHeight(1440);
    ((ChartPanel) chartPanel).setMaximumDrawWidth(2560);
}

From source file:com.yahoo.egads.utilities.GUIUtils.java

/**
 * Compute the time-series of anomalies.
 *//*from  w w w.j  a v a2 s.c o  m*/
public void addAnomalyTS(CombinedDomainXYPlot plot, DataSequence observedSeries, DataSequence expectedSeries) {
    // Compute the time-series of errors.
    HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries);
    Float sDAutoSensitivity = (float) 0.0;
    Float amntAutoSensitivity = (float) 0.0;
    if (config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT") != null) {
        amntAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT"));
    }

    if (config.getProperty("AUTO_SENSITIVITY_SD") != null) {
        sDAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_SD"));
    }

    String errorDebug = "";
    for (int i = 0; i < (aes.getIndexToError().keySet()).size(); i++) {
        Float[] fArray = (allErrors.get(aes.getIndexToError().get(i)))
                .toArray(new Float[(allErrors.get(aes.getIndexToError().get(i))).size()]);
        XYDataset data1 = createDataset(fArray, aes.getIndexToError().get(i));
        XYItemRenderer renderer1 = new StandardXYItemRenderer();
        NumberAxis rangeAxis1 = new NumberAxis(aes.getIndexToError().get(i));
        XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
        // Get threshold.
        Float d = AutoSensitivity.getLowDensitySensitivity(fArray, sDAutoSensitivity, amntAutoSensitivity);
        subplot1.addRangeMarker(new ValueMarker(d));
        subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        plot.add(subplot1, 1);
        errorDebug += aes.getIndexToError().get(i) + ": " + d + " ";
    }

    System.out.println(errorDebug);
}

From source file:controletanquesproj1.Grafico.java

/**
 * Creates a chart.//from w  w w.  jav a 2 s . c o m
 * 
 * @param _datasets
 * @param datasets
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Amostra", // x axis label
            "Amplitude (V)", // y axis label
            getDatasets()[0], // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.getRangeAxis(0).setRange(-30, 30);

    final NumberAxis axis2 = new NumberAxis("Altura (cm)");
    axis2.setAutoRange(true);
    axis2.setAutoRangeIncludesZero(false);

    //axis2.setRange(-4.9, 34.9);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, getDatasets()[1]);
    plot.mapDatasetToRangeAxis(1, 1);

    /*
    getRenderer().setSeriesLinesVisible(0, true);
    getRenderer().setSeriesShapesVisible(0, false);
    getRenderer().setSeriesShapesVisible(1, false);
    getRenderer().setSeriesShapesVisible(2, false);
    getRenderer().setSeriesLinesVisible(3, true);
    getRenderer().setSeriesShapesVisible(3, false);
    */

    renderer[0].setBaseShapesVisible(false);
    renderer[0].setAutoPopulateSeriesPaint(true);

    plot.setRenderer(renderer[0]);

    renderer[1] = new XYLineAndShapeRenderer();
    renderer[1].setBaseLinesVisible(true);
    renderer[1].setBaseShapesVisible(true);

    plot.setRenderer(1, renderer[1]);

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

    return chart;

}

From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java

private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints,
        XYDataset xyData) {/*from   ww  w.ja  v a 2  s .  c o  m*/
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0], maxs[0]);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);

    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

From source file:asl.util.PlotMaker.java

public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend,
        String eventString, String plotString) {

    // Expecting 9 channels packed like:            Panel   Trace1  Trace2  Trace3
    // channels[0] = 00-LHZ                           1     00-LHZ   10-LHZ   20-LHZ
    // channels[1] = 00-LHND                          2     00-LHND  10-LHND  20-LHND
    // channels[2] = 00-LHED                          3     00-LHED  10-LHED  20-LHED
    // channels[3] = 10-LHZ                           
    // channels[4] = 10-LHND                          
    // channels[5] = 10-LHED                          
    // channels[6] = 20-LHZ                           
    // channels[7] = 20-LHND                         
    // channels[8] = 20-LHED                        

    final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString);
    final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString);
    File outputFile = new File(pngName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it "
                + " --> skip plot\n", pngName);
        return;//from   w  w  w. java  2s  .c  o m
    }

    if (channelData.size() != channels.length) {
        System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n",
                channels.length, channelData.size());
        return;
    }

    XYSeries[] series = new XYSeries[channels.length];
    for (int i = 0; i < channels.length; i++) {
        series[i] = new XYSeries(channels[i].toString());
        double[] data = channelData.get(i);
        //for (int k = 0; k < xsecs.length; k++){
        for (int k = 0; k < data.length; k++) {
            series[i].add(xsecs[k], data[k]);
        }
    }

    // I. Panel I = Verticals

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    double[] data = channelData.get(0);
    double ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green };
    for (int i = 0; i < paints.length; i++) {
        renderer.setSeriesPaint(i, paints[i]);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, false);
    }

    final NumberAxis verticalAxis = new NumberAxis("Displacement (m)");
    verticalAxis.setRange(new Range(-ymax, ymax));
    //verticalAxis.setTickUnit( new NumberTickUnit(5) );

    final NumberAxis horizontalAxis = new NumberAxis("Time (s)");
    horizontalAxis.setRange(new Range(nstart, nend));
    //horizontalAxis.setRange( new Range(0.00009 , 110) );
    final NumberAxis hAxis = new NumberAxis("Time (s)");
    hAxis.setRange(new Range(nstart, nend));

    final XYSeriesCollection seriesCollection1 = new XYSeriesCollection();
    seriesCollection1.addSeries(series[0]);
    seriesCollection1.addSeries(series[3]);
    seriesCollection1.addSeries(series[6]);
    //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer);
    //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer);
    final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer);
    double x = .95 * xsecs[nend];
    double y = .90 * ymax;
    XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y);
    annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot1.addAnnotation(annotation1);

    // II. Panel II = North

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    data = channelData.get(1);
    ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }
    final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)");
    verticalAxisN.setRange(new Range(-ymax, ymax));

    final XYSeriesCollection seriesCollection2 = new XYSeriesCollection();
    seriesCollection2.addSeries(series[1]);
    seriesCollection2.addSeries(series[4]);
    seriesCollection2.addSeries(series[7]);
    final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer);
    XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y);
    annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot2.addAnnotation(annotation2);

    // III. Panel III = East

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    data = channelData.get(2);
    ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }
    final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)");
    verticalAxisE.setRange(new Range(-ymax, ymax));

    final XYSeriesCollection seriesCollection3 = new XYSeriesCollection();
    seriesCollection3.addSeries(series[2]);
    seriesCollection3.addSeries(series[5]);
    seriesCollection3.addSeries(series[8]);
    final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer);
    XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y);
    annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot3.addAnnotation(annotation3);

    //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL );
    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.add(xyplot1, 1);
    combinedPlot.add(xyplot2, 1);
    combinedPlot.add(xyplot3, 1);
    combinedPlot.setGap(15.);

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle));

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }

}

From source file:org.cds06.speleograph.data.fileio.SpeleoFileReader.java

/**
 * Read a file with SpeleoGraph File Format.
 *
 * @param file The file to read/*from w ww .j  a  v  a 2  s  .c  o  m*/
 * @throws FileReadingError On error while reading the file
 */
@SuppressWarnings("HardCodedStringLiteral")
@Override
public void readFile(File file) throws FileReadingError {
    InputStreamReader streamReader;
    try {
        streamReader = new InputStreamReader(new FileInputStream(file), "UTF-8"); // NON-NLS
    } catch (UnsupportedEncodingException | FileNotFoundException e) {
        log.error("Can not access to file", e);
        throw new FileReadingError(I18nSupport.translate("error.canNotOpenFile", file.getName()),
                FileReadingError.Part.HEAD, e);
    }
    CSVReader reader = new CSVReader(streamReader, ';', '"');
    axes = new ArrayList<>();
    typeAxesChecker = new ArrayList<>();
    String[] line;
    try {
        line = reader.readNext();
    } catch (IOException e) {
        throw new FileReadingError(I18nSupport.translate("error.canNotReadFileOrEmpty"),
                FileReadingError.Part.HEAD, e);
    }
    int size, state = CHECKING;
    HeaderInformation headers = new HeaderInformation();
    DateInformation date = new DateInformation();
    headers.setDateInformation(date);
    while (line != null) {
        size = line.length;
        if (size == 0) {
            log.info("Empty line while reading file, just continue our walk.");
            continue;
        }
        String firstLineElement = line[0];
        if (firstLineElement.equals("eof"))
            break; // Force end for reading NON-NLS
        switch (state) {
        case CHECKING:
            if (!SPELEOGRAPH_FILE_HEADER.equals(firstLineElement))
                throw NOT_SPELEO_FILE;
            state = FINDING_HEADERS;
            break;
        case FINDING_HEADERS:
            if ("headers".equals(firstLineElement))
                state = READING_HEADERS; // NON-NLS
            break;
        case READING_HEADERS:
            switch (firstLineElement) {
            case "data":
                state = READING_DATA;
                break;
            case "date":
                readDateHeaderLine(date, line);
                break;
            case "axis":
                try {
                    NumberAxis axis = new NumberAxis(line[2]);
                    axis.setLowerBound((DecimalFormat.getInstance().parse(line[3])).doubleValue());
                    axis.setUpperBound(DecimalFormat.getInstance().parse(line[4]).doubleValue());
                    typeAxesChecker.add(Integer.parseInt(line[1]), new Properties(line).getBoolean("type"));
                    axes.add(Integer.parseInt(line[1]), axis);
                } catch (Exception e) {
                    log.error("Can not read axis", e);
                }
                break;
            case "chart":

                break;
            default:
                readSeriesHeaderLine(file, line, headers);
            }
            break;
        case READING_DATA:
            if (size <= 1)
                break;
            headers.read(line);
            break;
        default:
            log.info("State error in reading");
        }
        try {
            line = reader.readNext();
        } catch (IOException e) {
            log.debug("None next lines", e);
        }
    }
    Series.notifyInstanceListeners();
    log.info("File reading is ended");
}

From source file:com.jaxzin.iraf.forecast.swing.JForecaster.java

@SuppressWarnings({ "FieldRepeatedlyAccessedInMethod" })
private void customizeChart(final JFreeChart chart) {
    // Set the transparency of the histogram bars
    //        chart.getXYPlot().setForegroundAlpha(0.5f);
    // Lock the y-axis to 0.0->0.5

    // Customize the y-logAxis
    logAxis = new LogarithmicAxis("Account Value");
    logAxis.setAutoRange(true);/*from  w w w .  j a v a 2 s .  c  o m*/
    logAxis.setAllowNegativesFlag(true);
    logAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance());

    linearAxis = new NumberAxis("Account Value");
    linearAxis.setAutoRange(true);
    linearAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance());

    //noinspection ConditionalExpression
    chart.getXYPlot().setRangeAxis(controlPanel.isLogScale() ? logAxis : linearAxis);

    // Customize the legend (add title, reverse order, attach to right side)
    final BlockContainer legendWrap = new BlockContainer();
    final Block title = new LabelBlock("Percentiles");
    legendWrap.setArrangement(new ColumnArrangement());
    legendWrap.add(title);
    final LegendTitle legendTitle = new LegendTitle(new ReversedLegendItemSource(chart.getXYPlot()),
            new ColumnArrangement(), new ColumnArrangement());
    legendWrap.add(legendTitle);
    chart.getLegend().setWrapper(legendWrap);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    // Customize the format of the tooltips
    chart.getXYPlot().getRenderer().setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("yyyy"), NumberFormat.getCurrencyInstance()));
}

From source file:org.jfree.chart.demo.ContourPlotDemo.java

/**
 * Creates a ContourPlot chart./*from w  ww. ja  va2s .  c om*/
 *
 * @return the chart.
 */
private JFreeChart createContourPlot() {

    final String title = "Contour Plot";
    final String xAxisLabel = "X Values";
    final String yAxisLabel = "Y Values";
    final String zAxisLabel = "Color Values";

    if (xIsDate) {
        this.xAxis = new DateAxis(xAxisLabel);
        xIsLog = false; // force axis to be linear when displaying dates
    } else {
        if (xIsLog) {
            this.xAxis = new LogarithmicAxis(xAxisLabel);
        } else {
            this.xAxis = new NumberAxis(xAxisLabel);
        }
    }

    if (yIsLog) {
        this.yAxis = new LogarithmicAxis(yAxisLabel);
    } else {
        this.yAxis = new NumberAxis(yAxisLabel);
    }

    if (zIsLog) {
        this.zColorBar = new ColorBar(zAxisLabel);
    } else {
        this.zColorBar = new ColorBar(zAxisLabel);
    }

    if (this.xAxis instanceof NumberAxis) {
        ((NumberAxis) this.xAxis).setAutoRangeIncludesZero(false);
        ((NumberAxis) this.xAxis).setInverted(xIsInverted);
    }

    this.yAxis.setAutoRangeIncludesZero(false);

    this.yAxis.setInverted(yIsInverted);

    if (!xIsDate) {
        ((NumberAxis) this.xAxis).setLowerMargin(0.0);
        ((NumberAxis) this.xAxis).setUpperMargin(0.0);
    }

    this.yAxis.setLowerMargin(0.0);
    this.yAxis.setUpperMargin(0.0);

    this.zColorBar.getAxis().setInverted(zIsInverted);
    this.zColorBar.getAxis().setTickMarksVisible(true);

    final ContourDataset data = createDataset();

    final ContourPlot plot = new ContourPlot(data, this.xAxis, this.yAxis, this.zColorBar);

    if (xIsDate) {
        ratio = Math.abs(ratio); // don't use plot units for ratios when x axis is date
    }
    plot.setDataAreaRatio(ratio);

    final JFreeChart chart = new JFreeChart(title, null, plot, false);
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    return chart;

}