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:msec.org.Tools.java

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }/*from w w  w. j av  a  2  s.c  o  m*/
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }

    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:bc.ui.swing.charts.LineChart.java

public void setModel(LineVisualModel line) {
    XYDataset dataset = createDataset(line);
    JFreeChart chart = ChartFactory.createXYLineChart(line.getTitle(), // chart title
            line.getDomainAxisLabel(), // x axis label
            line.getRangeAxisLabel(), // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*w  w  w  .j  av a 2  s  .  c  o m*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

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

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

    renderer.setSeriesPaint(0, new Color(153, 215, 255));

    removeAll();
    chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java

/**
 * @param observationCollection/*w w w  . j  ava 2 s  .co  m*/
 * @param screenW
 * @param screenH
 * @param bbox
 * @param selectedFeatures
 *        the Features of Interest for which a chart shall be renderered.
 */
public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon,
        int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) {
    if (selectedFeaturesCache == null) {
        selectedFeaturesCache = selectedFeatures;
    }

    // before starting to render --> run garbageCollection
    Runtime.getRuntime().gc();
    LOGGER.info("Garbage Collection done.");
    // --

    String[] observedProperties;
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {
        throw new IllegalArgumentException("no observedProperties found.");
    }

    // find tuples:
    if (obsValues4FOI == null) {
        obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache,
                observedProperties, true);
    }

    ContextBoundingBox contextBBox = new ContextBoundingBox(bbox);

    BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    // draw white background:
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, screenW, screenH);

    g.setColor(Color.BLACK);

    for (OXFFeature chartFeature : selectedFeaturesCache) {

        //
        // CACHING: create Plot for each "chart feature" and add it to the cache:
        //
        if (!chartCache.containsKey(chartFeature)) {
            Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature);

            // draw a chart if there are tuples for the chartFeature available:
            if (timeMap != null) {
                XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap);
                chartCache.put(chartFeature, chart);
            }
        }

        //
        // draw the plots (which are in the cache):
        //
        Point pRealWorld = (Point) chartFeature.getGeometry();

        java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW,
                screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y));
        XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature);

        // if there is a plot in the cache for the chartFeature -> draw it:
        if (cachedPlot != null) {
            cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0),
                    (Double) obsValues4FOI.getMaximum(0));

            cachedPlot.draw(g,
                    new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT),
                    null, null, null);
        } else {
            g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT);
        }

        // draw point of feature:
        g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT);

    }

    return new StaticVisualization(image);
}

From source file:syg_Wykresy.PanelRysunek_Wykres.java

private void initGUI() {
    try {//  w ww .  ja v a 2  s.  c o m
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {

            XYSeries series = new XYSeries("Sygna "
                    + (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY ? "cigy" : "dyskretny"));
            double punkt;
            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY_wykres().size() <= 0) {
                punkt = this.sygnalWyswietlany.gett1();
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY_wykres(punkt);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY) {
                        if (this.sygnalWyswietlany.gettyp() != 9 && this.sygnalWyswietlany.gettyp() != 10)
                            ta = ta + this.sygnalWyswietlany.getkroczek();
                        else
                            ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                    } else {
                        if (this.sygnalWyswietlany.gettyp() != 9 && this.sygnalWyswietlany.gettyp() != 10)
                            ta = ta + this.sygnalWyswietlany.getkrok();
                        else
                            ta = ta + this.sygnalWyswietlany.getkrok() * 10;
                    }
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY_wykres().size() > 0) {
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY_wykres().size());
                for (int i = 0; i < iloscProbek; i++) {
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    series.add(ta, punkt);
                    ta = ta + this.sygnalWyswietlany.getkrok();
                }
            }

            XYSeriesCollection dataset = new XYSeriesCollection(series);
            JFreeChart chart;

            if ((this.sygnalWyswietlany.gettyp() != 9 && this.sygnalWyswietlany.gettyp() != 10)
                    && (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

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

            // JOptionPane.showMessageDialog(null, "Rysowanie wykresu...",
            // "PanelRysunek_Wykres", JOptionPane.INFORMATION_MESSAGE);

            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.hs.mannheim.modUro.diagram.JCellCountDiagram.java

protected JFreeChart createChart(XYDataset dataset, String name) {
    String title = name;/* w  ww  .j ava  2  s  . c o  m*/

    JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title
            "t", // x-axis label
            "n", // y-axis label
            dataset);

    String fontName = "Palatino";
    xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));

    XYPlot plot = (XYPlot) xyLineChart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLowerMargin(0.0);
    // plot.getRangeAxis().setRange(0.0, 1.01);
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    xyLineChart.getLegend().setFrame(BlockBorder.NONE);
    xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();
    // set the default stroke for all series
    int i = 0;
    for (String celltype : getTimeSeries().getDataSeriesNames()) {
        r.setSeriesPaint(i, CellTypeColor.getColor(celltype));
        i++;
    }
    r.setSeriesPaint(i, Color.BLACK);
    return xyLineChart;
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createAgentsChart() {
    JFreeChart chart = ChartFactory.createXYLineChart("Alive Agents", // the title of the chart
            "Time Step", // the label for the X axis
            "Alive Agents", // the label for the Y axis
            model.agents_series_coll, // the dataset for the chart
            PlotOrientation.VERTICAL, // the orientation of the chart
            true, // a flag specifying whether or not a legend is required
            true, // a flag specifying whether or not tooltips should be generated
            false); // a flag specifying whether or not the chart should generate URLs

    XYPlot plot = chart.getXYPlot();
    ValueAxis xAxis = plot.getDomainAxis();
    //xAxis.setFixedDimension(50);
    //System.out.println("agents time series chart created");
    ValueAxis axis1 = plot.getRangeAxis();
    //axis1.setRange(0,1750);
    //StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(0);

    /*Color purple = new Color(140,0,164);
    renderer.setSeriesPaint(0,purple);//from  ww w . jav a2 s .c om
            
    ((NumberAxis)axis1).setLabelPaint(purple);
    ((NumberAxis)axis1).setTickLabelPaint(purple);
            
    NumberAxis axis2 = new NumberAxis("Average Metabolic Rate");
            
    //axis2.setAutoRangeIncludesZero(false);
            
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection metab = new XYSeriesCollection(model.metabolism);
    plot.setDataset(1, metab);
            
    StandardXYItemRenderer rend2 = new StandardXYItemRenderer();
            
    //if (rend2 != null)
    rend2.setSeriesPaint(1, Color.BLACK);
    ((NumberAxis)axis2).setLabelPaint(Color.BLACK);
    ((NumberAxis)axis2).setTickLabelPaint(Color.BLACK);
            
    plot.setRenderer(1, rend2);
    plot.mapDatasetToRangeAxis(1, 1);
            
    NumberAxis axis3 = new NumberAxis("Age");
    plot.setRangeAxis(2, axis3);
    plot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection ageXYSeries= new XYSeriesCollection(model.age);
    plot.setDataset(2, ageXYSeries);
    //ValueAxis yAgeAxis = plot.getRangeAxis();
            
    axis3.setRange(0,80);
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    StandardXYItemRenderer rend3 = new StandardXYItemRenderer();
    //if (rend2 != null)
    rend3.setSeriesPaint(2, Color.BLUE);
    plot.setRenderer(2, rend3);
    plot.mapDatasetToRangeAxis(2, 2);
            
    NumberAxis axis4 = new NumberAxis("Alive Agents");
    plot.setRangeAxis(3, axis4);
    axis4.setRange(0,1500);
    axis4.setLabelPaint(Color.BLACK);
    axis4.setTickLabelPaint(Color.BLACK);
    plot.setRangeAxisLocation(3, AxisLocation.BOTTOM_OR_RIGHT);
    XYSeriesCollection agentsXYSeries= new XYSeriesCollection(model.agents_series);
    plot.setDataset(3, agentsXYSeries);
    //ValueAxis yAgentsAxis = plot.getRangeAxis();
            
            
    StandardXYItemRenderer rend4 = new StandardXYItemRenderer();
    //if (rend2 != null)
    rend4.setSeriesPaint(3, Color.BLACK);
    plot.setRenderer(3, rend4);
    plot.mapDatasetToRangeAxis(3, 3);
            
    //}
    //System.out.println("done creating chart"); */
    return chart;
}

From source file:gsn.charts.GsnChartJfreechart.java

public JFreeChart createChart(Collection<Data> datas) {
    TimeSeries t1 = new TimeSeries("S1");
    Iterator<Data> iter = datas.iterator();
    Data data;/* w  w  w . ja v a 2 s .  co m*/
    while (iter.hasNext()) {
        data = iter.next();
        t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()),
                TimeZone.getDefault()), data.getValue());
    }
    XYDataset dataset = new TimeSeriesCollection(t1);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    chart.setBackgroundPaint(Color.WHITE);
    //
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("No Data to Display");
    plot.setDomainGridlinesVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setInsets(new RectangleInsets(5, 14, 0, 5));
    //
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(ssdf);
    axis.setTickLabelFont(TICK_FONT);
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickLabelFont(TICK_FONT);
    //
    return chart;
}

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

private JFreeChart createChart(final XYDataset dataset) {

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

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    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 rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;

}

From source file:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

/**
 * Constructor//from   w ww .j  a  v  a2  s .  com
 */
public ManualZoomDialog(Window parent, XYPlot plot) {

    initOwner(parent);

    setTitle("Manual zoom");

    setGraphic(new ImageView("file:icons/axesicon.png"));

    getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    xAxis = (NumberAxis) plot.getDomainAxis();
    yAxis = (NumberAxis) plot.getRangeAxis();

    try {
        URL layersDialogFXML = getClass().getResource(DIALOG_FXML);
        FXMLLoader loader = new FXMLLoader(layersDialogFXML);
        loader.setController(this);
        GridPane grid = loader.load();
        getDialogPane().setContent(grid);
    } catch (Exception e) {
        e.printStackTrace();
    }

    final Button btOk = (Button) getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(ActionEvent.ACTION, event -> {
        commitChanges(event);
    });

}

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

/**
 * //from  w  w w  . j  a va2  s  .  c om
 * Domain and Range axes need to share the same unit (e.g. mm)
 * 
 * @param myChart
 * @return
 */
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
    makeChartResizable(myChart);
    // paint on a ghost panel
    JPanel parent = (JPanel) myChart.getParent();
    JPanel p = new JPanel();
    p.removeAll();
    p.add(myChart, BorderLayout.CENTER);
    p.setBounds(myChart.getBounds());
    myChart.paintImmediately(myChart.getBounds());
    p.removeAll();
    parent.add(myChart);

    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Rectangle2D chartArea = info.getChartArea();

    // calc title space: will be added later to the right plot size
    double titleWidth = chartArea.getWidth() - dataArea.getWidth();
    double titleHeight = chartArea.getHeight() - dataArea.getHeight();

    // calc right plot size with axis dim.
    // real plot width is given by factor;
    double realPH = chartHeight - titleHeight;

    // ranges
    ValueAxis domainAxis = plot.getDomainAxis();
    org.jfree.data.Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    org.jfree.data.Range y = rangeAxis.getRange();

    // real plot height can be calculated by
    double realPW = realPH / y.getLength() * x.getLength();

    double width = realPW + titleWidth;

    return width;
}