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

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

Introduction

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

Prototype

public ValueAxis getRangeAxis() 

Source Link

Document

Returns the range axis for the plot.

Usage

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

public void dataDistributed(CQRowSetEvent e) {
    try {//from   w w w . j  ava2 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:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void mouseDragged(MouseEvent event) {
    try {/*from  w  ww.  j a  v  a  2  s.  c om*/
        if (this.panStartPoint != null) {
            Rectangle2D scaledDataArea = this.chartPanel.getScaledDataArea();

            this.panStartPoint = RefineryUtilities.getPointInRectangle(this.panStartPoint.getX(),
                    this.panStartPoint.getY(), scaledDataArea);
            Point2D panEndPoint = RefineryUtilities.getPointInRectangle(event.getX(), event.getY(),
                    scaledDataArea);

            // horizontal pan

            Plot plot = this.chartPanel.getChart().getPlot();
            if (plot instanceof XYPlot) {
                XYPlot hvp = (XYPlot) plot;
                ValueAxis xAxis = hvp.getDomainAxis();

                if (xAxis != null) {
                    double translatedStartPoint = xAxis.java2DToValue((float) panStartPoint.getX(),
                            scaledDataArea, hvp.getDomainAxisEdge());
                    double translatedEndPoint = xAxis.java2DToValue((float) panEndPoint.getX(), scaledDataArea,
                            hvp.getDomainAxisEdge());
                    double dX = translatedStartPoint - translatedEndPoint;

                    double oldMin = xAxis.getLowerBound();
                    double newMin = oldMin + dX;

                    double oldMax = xAxis.getUpperBound();
                    double newMax = oldMax + dX;

                    // do not pan out of range
                    if (newMin >= hvp.getDataRange(xAxis).getLowerBound()
                            && newMax <= hvp.getDataRange(xAxis).getUpperBound()) {
                        xAxis.setLowerBound(newMin);
                        xAxis.setUpperBound(newMax);
                    }
                }
            }

            // vertical pan (1. Y-Axis)

            if (plot instanceof XYPlot) {
                XYPlot vvp = (XYPlot) plot;
                ValueAxis yAxis = vvp.getRangeAxis();

                if (yAxis != null) {
                    double translatedStartPoint = yAxis.java2DToValue((float) panStartPoint.getY(),
                            scaledDataArea, vvp.getRangeAxisEdge());
                    double translatedEndPoint = yAxis.java2DToValue((float) panEndPoint.getY(), scaledDataArea,
                            vvp.getRangeAxisEdge());
                    double dY = translatedStartPoint - translatedEndPoint;

                    double oldMin = yAxis.getLowerBound();
                    double newMin = oldMin + dY;

                    double oldMax = yAxis.getUpperBound();
                    double newMax = oldMax + dY;

                    // do not pan out of range
                    if (newMin >= yMin && newMax <= yMax) {
                        yAxis.setLowerBound(newMin);
                        yAxis.setUpperBound(newMax);
                    }
                }
            }

            // for the next time
            this.panStartPoint = panEndPoint;
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createSingleChart() {
    XYDataset xydatasetArray[] = createDataset_CallsPerSecond_AvgResponseTime();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone result", "Calls per second",
            "Avg response time", xydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setAutoRange(true);/*  w  ww.ja va 2s  . c  om*/
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private final void setTheme(final JFreeChart chart) {
    final XYPlot plot = (XYPlot) chart.getPlot();
    final XYBarRenderer r = (XYBarRenderer) plot.getRenderer();
    final StandardXYBarPainter bp = new StandardXYBarPainter();
    r.setBarPainter(bp);/*from  ww  w .  j av  a 2  s .  c  o m*/
    // set Bar Color
    r.setSeriesPaint(0, Color.gray);
    r.setSeriesOutlinePaint(0, Color.gray);
    r.setShadowVisible(false);
    r.setDrawBarOutline(true);
    setBackgroundDefault(chart);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setTickMarksVisible(false);
    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setTickMarksVisible(false);
}

From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo2.java

/**
 * Creates a chart./* ww w .  j a  v  a2 s . com*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

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

    setXSummary(dataset);
    return chart;

}

From source file:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart from XML output file", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  w ww  .j  ava  2 s  .  c o m*/

    // 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.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);

    // 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:speedbagalg.OscopeView.java

/**
 * Creates new form OscopeView//from w  w w  .j  a  v  a2  s . c  o m
 */
/*    
    public OscopeView(String fileName)
    {
this.fileName = fileName;
initComponents();
updateThread = new RunnableMember2(this, "updateGUI");
ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
// create a dataset...
int maxAge = 2400;
this.xData = new TimeSeries("X axis");
this.xData.setMaximumItemAge(maxAge);
this.yData = new TimeSeries("Y axis");
this.yData.setMaximumItemAge(maxAge);
this.zData = new TimeSeries("Z axis");
this.zData.setMaximumItemAge(maxAge);
this.averageData = new TimeSeries("Avg. Data");
this.averageData.setMaximumItemAge(maxAge);
//this.windSpeedSeries = new TimeSeries("Wind Speed");
//this.windSpeedSeries.setMaximumItemAge(maxAge);
//this.rainSeries = new TimeSeries("Rain 24hrs");
//this.rainSeries.setMaximumItemAge(maxAge);
        
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(xData);
dataset.addSeries(yData);
dataset.addSeries(zData);
dataset.addSeries(averageData);
        
//dataset.addSeries(windSpeedSeries);
//dataset.addSeries(rainSeries);
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Accel Data",
        "Time",
        "Value",
        dataset,
        true,
        true,
        false);
final XYPlot plot = chart.getXYPlot();
        
ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
axis = plot.getRangeAxis();
axis.setRange(-1000.0, 10000.0);
        
chart.setBackgroundPaint(Color.white);
        
//XYPlot plot = (XYPlot) chart.getPlot();
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);
        
// create and display a frame...
thePanel = new ChartPanel(chart);
        
Dimension d = new Dimension(200, 100);
thePanel.setSize(d);
thePanel.setPreferredSize(d);
BorderLayout layout = new BorderLayout();
jPanelOscope.setLayout(layout);
jPanelOscope.add(thePanel, BorderLayout.CENTER);
        
plotXCheckBox.setSelected(plotX);
plotYCheckBox.setSelected(plotY);
plotZCheckBox.setSelected(plotZ);
    }
*/
public OscopeView(String fileName) {
    this.fileName = fileName;
    initComponents();
    updateThread = new RunnableMember2(this, "updateGUI");
    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
    // create a dataset...
    this.xData = new XYSeries("Min");
    //this.xData.setMaximumItemAge(maxAge);
    this.yData = new XYSeries("Peak");
    //this.yData.setMaximumItemAge(maxAge);
    this.zData = new XYSeries("Z axis");
    //this.zData.setMaximumItemAge(maxAge);
    this.averageData = new XYSeries("Avg. Data");
    //this.averageData.setMaximumItemAge(maxAge);
    //this.windSpeedSeries = new TimeSeries("Wind Speed");
    //this.windSpeedSeries.setMaximumItemAge(maxAge);
    //this.rainSeries = new TimeSeries("Rain 24hrs");
    //this.rainSeries.setMaximumItemAge(maxAge);

    final XYSeriesCollection dataset = new XYSeriesCollection();
    //SlidingCategoryDataset dataset = new SlidingCategoryDataset(0, 10);
    dataset.addSeries(xData);
    dataset.addSeries(yData);
    dataset.addSeries(zData);
    dataset.addSeries(averageData);

    //dataset.addSeries(windSpeedSeries);
    //dataset.addSeries(rainSeries);
    chart = ChartFactory.createXYLineChart("Accel Data", "Time", "Value", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();

    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(false);
    axis.setRange(minStart, maxDomain);
    axis = plot.getRangeAxis();
    axis.setRange(vMin, vMax);

    chart.setBackgroundPaint(Color.white);

    //XYPlot plot = (XYPlot) chart.getPlot();
    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);

    // create and display a frame...
    thePanel = new ChartPanel(chart);

    Dimension d = new Dimension(200, 100);
    thePanel.setSize(d);
    thePanel.setPreferredSize(d);
    BorderLayout layout = new BorderLayout();
    jPanelOscope.setLayout(layout);
    jPanelOscope.add(thePanel, BorderLayout.CENTER);

    plotXCheckBox.setSelected(plotX);
    plotYCheckBox.setSelected(plotY);
    plotZCheckBox.setSelected(plotZ);

    vMaxSpinner.setValue(vMax);
}

From source file:Main.Chart.java

/**
 * Creates a chart./*  www . j  a  v a 2s.  co  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Weather Forecast", // chart title
            "Time", // x axis label
            "Temperature", // y axis label
            dataset, // 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.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);

    // 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:org.zaproxy.zap.extension.customFire.ScanProgressDialog.java

/**
 * //from   w  w  w  . j av a 2 s. c  om
 * @param dataset
 * @return JFreeChart `
 */
private JFreeChart createChart(final XYDataset dataset) {

    JFreeChart result = ChartFactory.createTimeSeriesChart(null, "Time", "Response/seconds", dataset, true,
            false, false);
    XYPlot plot = result.getXYPlot();
    ValueAxis daxis = plot.getDomainAxis();
    daxis.setAutoRange(true);
    daxis.setAutoRangeMinimumSize(60000.0);

    plot.getRangeAxis().setAutoRangeMinimumSize(20);

    return result;
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.ClinicalPlot.java

private void createChart() {

    //String xLabel = factor1.toString();
    String xLabel = factor1AxisLabel;
    //String yLabel = factor2.toString();
    String yLabel = factor2AxisLabel;

    clinicalChart = ChartFactory.createScatterPlot("Clinical Plot", xLabel, yLabel, null,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) clinicalChart.getPlot();

    buildLegend();/*from  w ww.j  a  v a2  s.c  o  m*/

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.

    domainAxis.setAutoRangeIncludesZero(false);

    //get domain and range of the axis.
    DataRange domainAxisLimits = getDataRange(dataPoints, factor1, true);
    DataRange rangeAxisLimits = getDataRange(dataPoints, factor2, true);

    //domainAxis.setRange(domainAxisLimits.getMinRange(), domainAxisLimits.getMaxRange());
    //rangeAxis.setRange(rangeAxisLimits.getMinRange(), rangeAxisLimits.getMaxRange());

    double domainMax = Math.max(100.0, domainAxisLimits.getMaxRange()) + 5.0;
    double rangeMax = Math.max(100.0, rangeAxisLimits.getMaxRange()) + 5.0;

    domainAxis.setRange(0.0, domainMax);
    rangeAxis.setRange(0.0, rangeMax);

    System.out.println("domainAxis=" + domainAxis.getLabel());
    System.out.println("rangeAxis=" + rangeAxis.getLabel());

    createGlyphsAndAddToPlot(plot);
}