Example usage for org.jfree.data.contour ContourDataset getXValues

List of usage examples for org.jfree.data.contour ContourDataset getXValues

Introduction

In this page you can find the example usage for org.jfree.data.contour ContourDataset getXValues.

Prototype

public Number[] getXValues();

Source Link

Document

Returns the array of Numbers representing the x data values.

Usage

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

/**
 * Creates a ContourPlot chart.// ww w  .  j av a  2  s  .  c o m
 *
 * @return the ContourPlot 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);

    if (!xIsDate) {
        this.xAxis.setRange(10.5, 15.0);
    }
    this.yAxis.setRange(3.5, 7.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
    }

    if (asPoints) {
        plot.setRenderAsPoints(true);
    }
    plot.setDataAreaRatio(ratio);

    if (annotate) {
        if (asPoints) {
            final Number[] xValues = data.getXValues();
            final Number[] yValues = data.getYValues();
            //Number[] zValues = data.getZValues();

            final Font font = new Font("SansSerif", Font.PLAIN, 20);

            for (int i = 0; i < xValues.length; i++) {
                final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i),
                        xValues[i].doubleValue(), yValues[i].doubleValue());
                xyAnn.setFont(font);
                plot.addAnnotation(xyAnn);
            }
        } else {
            final Font font = new Font("SansSerif", Font.PLAIN, 20);

            for (int i = 0; i < this.tmpDoubleX.length; i++) {
                final XYTextAnnotation xyAnn = new XYTextAnnotation(Integer.toString(i), this.tmpDoubleX[i],
                        this.tmpDoubleY[i]);
                xyAnn.setFont(font);
                plot.addAnnotation(xyAnn);
            }
        }

    }

    if (fillOutline || drawOutline) {
        initShoreline();
        plot.setClipPath(new ClipPath(this.xOutline, this.yOutline, true, fillOutline, drawOutline));
    }

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

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    return chart;

}