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.vimarsha.ui.TimeSlicedClassiferForm.java

private JFreeChart createChart(XYSeriesCollection dataSet, String chartTitle) {
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Time slice number", "Classification",
            dataSet, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();

    range.setRange(0, 1.1);//from   w  ww . j  a  v  a  2  s.  c o  m
    TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(0));
    units.add(new NumberTickUnit(0.5));
    units.add(new NumberTickUnit(1));

    range.setStandardTickUnits(units);
    range.setNumberFormatOverride(new DecimalFormat() {
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            if (number == 1)
                return toAppendTo.append("badfs");
            else if (number == 0.5)
                return toAppendTo.append("badma");
            else
                return toAppendTo.append("good");
        }
    });

    return chart;
}

From source file:org.yccheok.jstock.gui.charting.DynamicChart.java

public void showNewJDialog(java.awt.Frame parent, String title) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(this.price);

    JFreeChart freeChart = ChartFactory.createTimeSeriesChart(title, GUIBundle.getString("DynamicChart_Date"),
            GUIBundle.getString("DynamicChart_Price"), dataset, true, true, false);

    freeChart.setAntiAlias(true);/*from  www.  j  a  v a 2s. com*/

    XYPlot plot = freeChart.getXYPlot();
    NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    DecimalFormat format = new DecimalFormat("00.00");
    rangeAxis1.setNumberFormatOverride(format);

    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#")));

    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);

    ChartPanel _chartPanel = new ChartPanel(freeChart, true, true, true, true, true);
    JDialog dialog = new JDialog(parent, title, false);
    dialog.getContentPane().add(_chartPanel, java.awt.BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    final java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    dialog.setBounds((screenSize.width - 750) >> 1, (screenSize.height - 600) >> 1, 750, 600);
    dialog.setVisible(true);
}

From source file:monitoring.suhu.DynamicCharts.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Temperature Graph", "Time", "Celcius",
            dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from   w ww  .j  a va  2s  .  c  om
    axis.setFixedAutoRange(60000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(0.0, 50.0);
    return result;
}

From source file:com.sciaps.listener.JFreeChartMouseListener.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {

    if (cme.getTrigger().isControlDown()) {

        Point2D p = cme.getTrigger().getPoint();
        Rectangle2D plotArea = chartPanel_.getScreenDataArea();
        XYPlot plot = (XYPlot) jFreeChart_.getPlot();
        double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
        double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());

        if (callback_ != null) {
            callback_.jFreeChartOnClicked(chartX, chartY);
        }/*from  w  w w.  ja  v  a  2 s .c  om*/
    }
}

From source file:net.sf.maltcms.chromaui.charts.format.ScaledNumberFormatter.java

/**
 *
 * @param cce//from   w  w w.ja va  2 s . c o  m
 */
@Override
public void chartChanged(ChartChangeEvent cce) {
    ChartChangeEventType ccet = cce.getType();
    if (ccet == ChartChangeEventType.DATASET_UPDATED || ccet == ChartChangeEventType.NEW_DATASET) {
        if (cce.getSource() != (this)) {
            Plot p = cce.getChart().getPlot();
            if (p instanceof XYPlot) {
                XYPlot xyp = (XYPlot) p;
                Range axisRange = xyp.getRangeAxis().getRange();
                ;
                if (relativeMode) {
                    int cnt = xyp.getDatasetCount();
                    Range r = new Range(0, 1);
                    for (int i = 0; i < cnt; i++) {
                        Dataset d = xyp.getDataset(i);
                        if (d != null && d instanceof XYDataset) {
                            XYDataset xyd = (XYDataset) d;
                            Range dr = DatasetUtilities.findRangeBounds(xyd);
                            if (dr != null) {
                                r = new Range(Math.min(r.getLowerBound(), dr.getLowerBound()),
                                        Math.max(r.getUpperBound(), dr.getUpperBound()));

                            }
                        } else {
                            throw new NotImplementedException(
                                    "No support yet for dataset of type: " + d.getClass());
                        }
                    }
                    this.dataMin = Math.min(0, r.getLowerBound());
                    this.dataMax = r.getUpperBound();
                    cce.getChart().fireChartChanged();
                } else {
                    this.min = axisRange.getLowerBound();
                    this.max = axisRange.getUpperBound();
                    cce.getChart().fireChartChanged();
                }
            }
        }
    }
}

From source file:at.ac.tuwien.dsg.utility.DesignChart.java

public void chart(LinkedList<String> xValue, LinkedList<String> yValue) throws Exception {

    XYSeries series = new XYSeries("Sensory Data");
    final JFreeChart chart;

    //data assignment in the chart
    {//  w  ww  .ja v a2  s. c om
        for (int i = 0; i < xValue.size(); i++) {
            series.add(Double.parseDouble(xValue.get(i)), Double.parseDouble(yValue.get(i)));
        }

        final XYSeriesCollection data = new XYSeriesCollection(series);
        chart = ChartFactory.createXYLineChart("Graph Visualization", "collection_time", "collection_data",
                data, PlotOrientation.VERTICAL, true, true, false);
    }

    //design the plot of the chart
    {
        XYPlot xyPlot = chart.getXYPlot();
        NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
        NumberAxis yAxis = (NumberAxis) xyPlot.getRangeAxis();

        xAxis.setRange(20, 120);
        xAxis.setTickUnit(new NumberTickUnit(15));
        yAxis.setRange(947, 950);
        yAxis.setTickUnit(new NumberTickUnit(0.5));
    }

    //generation of the image  
    {
        try {

            BufferedImage img = chart.createBufferedImage(300, 200);
            //File outputfile = new File("./example/Sample.png");
            File outputfile = new File(
                    "/Users/dsg/Documents/phd/Big Demo/CloudLyra/Utils/JBPMEngine/example/Sample.png");
            ImageIO.write(img, "png", outputfile);

        } catch (Exception e) {
            System.out.println("exception occured in tomcat: " + e);
        }
    }

}

From source file:org.matsim.pt.analysis.RouteTimeDiagram.java

public void createGraph(final String filename, final TransitRoute route) {

    HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>();
    int idx = 0;/* w ww.  j  av  a2 s  .  c  om*/
    for (TransitRouteStop stop : route.getStops()) {
        stopIndex.put(stop.getStopFacility().getId(), idx);
        idx++;
    }

    HashSet<Id> vehicles = new HashSet<Id>();
    for (Departure dep : route.getDepartures().values()) {
        vehicles.add(dep.getVehicleId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    int numSeries = 0;
    double earliestTime = Double.POSITIVE_INFINITY;
    double latestTime = Double.NEGATIVE_INFINITY;

    for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) {
        if (vehicles.contains(entry.getKey())) {
            XYSeries series = new XYSeries("t", false, true);
            for (Tuple<Id, Double> pos : entry.getValue()) {
                Integer stopIdx = stopIndex.get(pos.getFirst());
                if (stopIdx != null) {
                    double time = pos.getSecond().doubleValue();
                    series.add(stopIdx.intValue(), time);
                    if (time < earliestTime) {
                        earliestTime = time;
                    }
                    if (time > latestTime) {
                        latestTime = time;
                    }
                }
            }
            dataset.addSeries(series);
            numSeries++;

        }
    }

    JFreeChart c = ChartFactory.createXYLineChart("Route-Time Diagram, Route = " + route.getId(), "stops",
            "time", dataset, PlotOrientation.VERTICAL, false, // legend?
            false, // tooltips?
            false // URLs?
    );
    c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));

    XYPlot p = (XYPlot) c.getPlot();

    p.getRangeAxis().setInverted(true);
    p.getRangeAxis().setRange(earliestTime, latestTime);
    XYItemRenderer renderer = p.getRenderer();
    for (int i = 0; i < numSeries; i++) {
        renderer.setSeriesPaint(i, Color.black);
    }

    try {
        ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:slash.navigation.converter.gui.elevationview.ElevationView.java

private XYPlot createPlot(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    plot.setForegroundAlpha(0.65F);//w  w w. jav  a  2 s  .  c o  m

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    Font font = new JLabel().getFont();
    rangeAxis.setLabelFont(font);

    NumberAxis valueAxis = (NumberAxis) plot.getDomainAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    valueAxis.setLowerMargin(0.0);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLabelFont(font);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{2}m @ {1} Km",
            NumberFormat.getIntegerInstance(), NumberFormat.getIntegerInstance()));
    return plot;
}

From source file:Utils.GeneradorDeGraficas.java

public JFreeChart graficarCostos(DeterministaGeneral general, String unidad) {
    XYDataset dataset;/*from ww w .  ja v  a 2 s  . co m*/

    dataset = createDatasetCosto(general, unidad);

    JFreeChart chart = ChartFactory.createXYLineChart("Anlisis de Costo de Inventario por " + unidad,
            "Cantidad de pedido", "Costo", dataset, PlotOrientation.VERTICAL, true, true, false);

    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.setSeriesPaint(4, black, true);
    renderer.setSeriesPaint(3, black, true);

    /* renderer.setShapesFilled(true);
     renderer.setShapesVisible(true);*/

    XYPlot plot2 = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) plot2.getRangeAxis();
    rangeAxis.setAutoRange(false);

    rangeAxis.setUpperBound(general.calcularCostoGrafica(general.calcularCantidadOptimaOrdenar()) * 2);

    return chart;
}

From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.AbstractPlot.java

/**
 * Configure the Y-axis: Adjust the range and specify tick units.
 *///from  ww w .j  a  va  2s .  c  o  m
protected void setRangeAxis(boolean hideDecimals, XYPlot plot) {
    if (hideDecimals) {
        plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    if (getDatasetSize() == 0) {
        plot.getRangeAxis().setRange(0.0, 1.0);
    } else {
        plot.getRangeAxis().setRange(getMinimumValue() - 1, getMaximumValue() + 1);
    }
}