Example usage for org.jfree.chart.plot XYPlot getDomainAxis

List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDomainAxis.

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Translates mouse coordinates to chart coordinates (xy-axis)
 * /*from  ww w .  j  a v a2s  . c om*/
 * @param myChart
 * @param mouseX
 * @param mouseY
 * @return Range as chart coordinates (never null)
 */
public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) {
    XYPlot plot = null;
    // find plot as parent of axis
    ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY);
    if (entity instanceof AxisEntity) {
        Axis a = ((AxisEntity) entity).getAxis();
        if (a.getPlot() instanceof XYPlot)
            plot = (XYPlot) a.getPlot();
    }

    ChartRenderingInfo info = myChart.getRenderingInfo();
    int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY));
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    if (subplot != -1)
        dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();

    // find subplot or plot
    if (plot == null)
        plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY);

    // coordinates
    double cx = 0;
    double cy = 0;
    if (plot != null) {
        // find axis
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();
        RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
        // parent?
        if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            domainAxis = pp.getDomainAxis();
            domainAxisEdge = pp.getDomainAxisEdge();
        }
        if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            rangeAxis = pp.getRangeAxis();
            rangeAxisEdge = pp.getRangeAxisEdge();
        }

        if (domainAxis != null)
            cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge);
        if (rangeAxis != null)
            cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge);
    }
    return new Point2D.Double(cx, cy);
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Receives notification of a plot change event.
 *
 * @param event the event./*from  www.  j av a 2  s  .  c om*/
 */
public void plotChanged(PlotChangeEvent event) {
    XYPlot plot = (XYPlot) event.getPlot();

    if (plot.getDomainAxis() != domainAxis) {
        if (domainAxis != null)
            domainAxis.removeChangeListener(this);
        domainAxis = plot.getDomainAxis();
        domainAxisLength = domainAxis.getRange().getLength();
        domainAxis.addChangeListener(this);
    }

    if (plot.getRangeAxis() != rangeAxis) {
        if (rangeAxis != null)
            rangeAxis.removeChangeListener(this);
        rangeAxis = plot.getRangeAxis();
        rangeAxisLength = rangeAxis.getRange().getLength();
        rangeAxis.addChangeListener(this);
    }
}

From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java

public void dataDistributed(CQRowSetEvent e) {
    try {//w  w w . j av  a2  s  .  c  o m
        base = 0;
        CQRowSet rs = (CQRowSet) e.getSource();

        CQRowSetMetaData meta = rs.getMetaData();

        if (chart == null) {
            c = new TimeSeriesCollection();
            boolean first_loop = true;
            rs.beforeFirst();
            String[] t_obj = new String[meta.getColumnCount()];
            String[] t_val = new String[meta.getColumnCount()];

            while (rs.next()) {
                for (int i = 1; i <= meta.getColumnCount(); i++) {
                    double val = 0;

                    t_obj[i - 1] = meta.getColumnName(i);

                    if (meta.getColumnTypeName(i).equals(DataTypes.STRING)) {
                        t_val[i - 1] = rs.getString(i);
                        continue;
                    }
                    if (meta.getColumnTypeName(i).equals(DataTypes.OBJECT)) {
                        t_val[i - 1] = rs.getObject(i).toString();
                        continue;
                    }
                    if (meta.getColumnTypeName(i).equals(DataTypes.LONG)) {
                        long lval = rs.getLong(i);
                        val = (double) lval;
                        t_val[i - 1] = String.valueOf(lval);
                    } else if (meta.getColumnTypeName(i).equals(DataTypes.DOUBLE)) {
                        val = rs.getDouble(i);
                        t_val[i - 1] = String.valueOf(val);
                    } else {
                        t_val[i - 1] = rs.getString(i);
                        continue;
                    }

                    if (val < 1000000 || Double.isNaN(val)) {
                        TimeSeries ts = updateTimeSeries(meta.getColumnName(i), i, val);
                    }

                }
                if (model == null) {
                    model = new DefaultTableModel(t_obj, 0);
                    getJTable().setModel(model);
                }

                model.addRow(t_val);
                while (model.getRowCount() > 100) {
                    model.removeRow(0);
                }

                first_loop = false;
            }

            chart = ChartFactory.createTimeSeriesChart("", "", "", c, true, true, true);

            XYPlot plot = chart.getXYPlot();
            plot.setBackgroundPaint(Color.BLACK);
            plot.setRangeGridlinePaint(Color.WHITE);
            plot.getDomainAxis().setAutoRange(true);
            plot.getRangeAxis().setAutoRange(true);

            ValueAxis axis = plot.getDomainAxis();
            axis.setLowerMargin(0.03);
            axis.setUpperMargin(0.03);

            ChartPanel panel = (ChartPanel) getJPanel();
            panel.setChart(chart);
        } else {
            String[] t_val = new String[meta.getColumnCount()];
            rs.beforeFirst();
            while (rs.next()) {
                for (int i = 1; i <= meta.getColumnCount(); i++) {
                    double val = 0;

                    if (meta.getColumnTypeName(i).equals(DataTypes.STRING)) {
                        t_val[i - 1] = rs.getString(i);
                        continue;
                    }
                    if (meta.getColumnTypeName(i).equals(DataTypes.OBJECT)) {
                        t_val[i - 1] = rs.getObject(i).toString();
                        continue;
                    }
                    if (meta.getColumnTypeName(i).equals(DataTypes.LONG)) {
                        long lval = rs.getLong(i);
                        val = (double) lval;
                        t_val[i - 1] = String.valueOf(lval);
                    } else if (meta.getColumnTypeName(i).equals(DataTypes.DOUBLE)) {
                        val = rs.getDouble(i);
                        t_val[i - 1] = String.valueOf(val);
                    } else {
                        t_val[i - 1] = rs.getString(i);
                        continue;
                    }

                    if (val < 1000000 || Double.isNaN(val)) {
                        TimeSeries ts = updateTimeSeries(meta.getColumnName(i), i, val);
                    }
                }

                model.addRow(t_val);
                while (model.getRowCount() > 100) {
                    model.removeRow(0);
                }
            }
            repaint();
        }
    } catch (CQException ce) {
        ce.printStackTrace();
    }
}

From source file:org.rdv.viz.spectrum.SpectrumAnalyzerPanel.java

/**
 * Initializes the chart./*from   ww  w  . j ava  2 s  .c om*/
 */
private void initChart() {
    xySeries = new SpectrumXYSeries("", false, false);

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    xySeriesCollection.addSeries(xySeries);

    chart = ChartFactory.createXYLineChart(null, "Frequency (Hz)", null, xySeriesCollection,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setAntiAlias(false);

    XYPlot xyPlot = (XYPlot) chart.getPlot();
    NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
    xAxis.setRange(0, sampleRate / 2);

    setChart(chart);
}

From source file:pharoslabut.logger.CompassLoggerGUI.java

/**
 * Creates a chart./*from  w w  w . j a va2  s .  c  om*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Proteus Robot Compass Measurements", // chart title
            "Time (s)", // x axis label
            "Angle (radians)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // 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 customization...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setRange(new Range(0, 140));

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    // change the auto tick unit selection to integer units only...
    //        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(new Range(-Math.PI, Math.PI));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a chart./*w  w w. j a  v  a2 s  .c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, true, false);

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:flexflux.analyses.result.ParetoAnalysisResult.java

public void plot() {

    XYSeriesCollection dataset = new XYSeriesCollection();

    int i = 1;/*from  ww  w .j  a v  a2s. com*/
    for (Objective obj : oneDResults.keySet()) {

        XYSeries series = new XYSeries(obj.getName());

        for (double val : oneDResults.get(obj)) {

            series.add(i, val);
        }

        dataset.addSeries(series);
        i++;
    }

    // create the chart...

    final JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Objectives", // x axis label
            "Values", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    ChartPanel chartPanel = new ChartPanel(chart);

    XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.GRAY);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLinesVisible(false);
    renderer.setShapesVisible(true);
    plot.setRenderer(renderer);

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

    JFrame frame = new JFrame("Pareto analysis one dimension results");
    frame.add(chartPanel);

    frame.pack();

    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setVisible(true);

    for (PP2DResult r : twoDResults.keySet()) {

        r.plot();

    }

    for (PP3DResult r : threeDResults.keySet()) {

        r.plot();

    }

}

From source file:org.rdv.viz.spectrum.SpectrumAnalyzerPanel.java

/**
 * Sets the sample rate. The sample rate must be positive.
 * /*from w w w  .j av a 2s  . c o m*/
 * @param sampleRate  the new sample rate
 */
public void setSampleRate(double sampleRate) {
    if (sampleRate <= 0) {
        throw new IllegalArgumentException("Sample rate must be positive.");
    }

    if (this.sampleRate == sampleRate) {
        return;
    }

    double oldSampleRate = this.sampleRate;
    this.sampleRate = sampleRate;

    firePropertyChange(SAMPLE_RATE_PROPERTY, oldSampleRate, sampleRate);

    // set the x-axis range
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
    xAxis.setRange(0, sampleRate / 2);

    plotSpectrum();
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a scatter plot/*from  ww  w .j  ava 2s  .c  o m*/
 * @param particles Particle data to use
 * @param title Title of the graph
 * @return a QImage
 */
public QImage createScatterPlot(final Particles3D particles, final String title, final String unit) {

    if (particles == null)
        return null;

    List<Particle3D> pars = particles.getParticles();

    final int count = pars.size();

    final double[][] data = new double[2][];
    data[0] = new double[count];
    data[1] = new double[count];

    int i = 0;
    for (Particle3D p : pars) {

        data[0][i] = p.getIntensity();
        data[1][i] = p.getVolume();
        i++;
    }

    DefaultXYDataset xydataset = new DefaultXYDataset();
    xydataset.addSeries("data", data);

    JFreeChart chart = ChartFactory.createScatterPlot(title, "Intensity", "Volume" + unitLegendCude(unit),
            xydataset, PlotOrientation.VERTICAL, false, true, false);

    addTransparency(chart);

    XYPlot xyplot = (XYPlot) chart.getPlot();
    XYDotRenderer xydotrenderer = new XYDotRenderer();
    xydotrenderer.setDotWidth(2);
    xydotrenderer.setDotHeight(2);
    xyplot.setRenderer(xydotrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setAutoRangeIncludesZero(false);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

/**
 * Decreases the range on the horizontal axis, centered about a Java2D x coordinate.
 * <P>/*from w w w  .ja v  a 2  s.  c om*/
 * The range on the x axis is multiplied by zoomFactor
 * 
 * @param x  the x coordinate in Java2D space.
 * @param zoomFactor  the zoomFactor < 1 == zoom in; else out.
 */
private void zoomHorizontal(double x, double zoomFactor) {

    JFreeChart chart = this.chartPanel.getChart();
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    if (chart.getPlot() instanceof XYPlot) {
        XYPlot hvp = (XYPlot) chart.getPlot();
        ValueAxis axis = hvp.getDomainAxis();
        if (axis != null) {
            double anchorValue = axis.java2DToValue((float) x, info.getPlotInfo().getDataArea(),
                    hvp.getDomainAxisEdge());
            if (zoomFactor < 1.0) {
                axis.resizeRange(zoomFactor, anchorValue);
            } else if (zoomFactor > 1.0) {
                Range range = hvp.getDataRange(axis);
                adjustRange(axis, range, zoomFactor, anchorValue);
            }
        }
    }
}