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.codehaus.mojo.chronos.chart.ChartUtil.java

public static XYPlot setupXYPlot(JFreeChart chart, DateFormat dateFormat) {
    XYPlot plot = chart.getXYPlot();

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(dateFormat);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return plot;//from   w  w  w  .j a  v a2 s .  com
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot//  w  w  w.  j a  va  2  s  .com
 * @param screenPoint
 * @param screenDataArea
 * @return
 */
public static Point translatePointToImageCoord(XYPlot plot, final Point screenPoint,
        final Rectangle2D screenDataArea) {
    final ValueAxis da = plot.getDomainAxis();
    final ValueAxis ra = plot.getRangeAxis();

    final double x = da.java2DToValue(screenPoint.getX(), screenDataArea, plot.getDomainAxisEdge());
    final double y = ra.java2DToValue(screenPoint.getY(), screenDataArea, plot.getRangeAxisEdge());

    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "{0} - {1}", new Object[] { x, y });

    if (x > 0 && y > 0) {
        return new Point((int) x, (int) y);
    }

    //        final double axisXperc = (x - plot.getDomainAxis().getLowerBound())
    //                / (plot.getDomainAxis().getUpperBound() - plot.getDomainAxis().getLowerBound());
    //        final double axisYperc = (y - plot.getRangeAxis().getLowerBound())
    //                / (plot.getRangeAxis().getUpperBound() - plot.getRangeAxis().getLowerBound());
    //
    //        System.out.println(axisXperc + " - " + axisYperc);
    //        final int newX = (int) (axisXperc * this.imageWidth);
    //        final int newY = (int) (axisYperc * this.imageHeight);
    return null;
}

From source file:ec.ui.view.ARPView.java

static JFreeChart createARPChart() {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();

    plot.setNoDataMessage("Drop data here");
    plot.getRangeAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.getDomainAxis().setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);

    ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false);

    return result;
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx,
        final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller,
        final java.util.Collection<String> attrs) throws Exception {
    final Instances dataSetWithTheGap = new Instances(pdataSet);
    for (int i = position; i < position + gapsize; i++)
        dataSetWithTheGap.instance(i).setMissing(attr);

    int[] arr = new int[] { attr.index(), dateIdx };
    for (final String sss : attrs) {
        arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() });
    }//from w w  w.  j  a  v a 2  s. c  om

    Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap,
            arr);
    filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0,
            filteredDsWithTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithTheGap.numInstances() - 1));

    final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap);
    final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds);

    Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr);
    filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0,
            filteredDsWithoutTheGap.numAttributes() - 1,
            Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize),
            Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize,
                    filteredDsWithoutTheGap.numInstances() - 1));

    diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes());
    for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) {
        diff.instance(i).setValue(diff.numAttributes() - 1,
                filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name())));
    }
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final java.util.List<String> toRemove = new java.util.ArrayList<String>();
    for (int j = 0; j < diff.numAttributes(); j++) {
        final String consideredAttrName = diff.attribute(j).name();
        if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name()))
            toRemove.add(consideredAttrName);
    }
    diff.setClassIndex(-1);
    for (final String ssss : toRemove)
        diff.deleteAttributeAt(diff.attribute(ssss).index());
    //System.out.println(attr.name()+"\n"+diff.toSummaryString());

    final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false,
            WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null);

    final XYPlot xyp = (XYPlot) cp.getChart().getPlot();
    xyp.getDomainAxis().setLabel("");
    xyp.getRangeAxis().setLabel("");

    final Marker gapBeginMarker = new ValueMarker(
            dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx));
    gapBeginMarker.setPaint(Color.RED);
    gapBeginMarker.setLabel("Gap begin");
    gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

    final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap
            .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx));
    gapEndMarker.setPaint(Color.RED);
    gapEndMarker.setLabel("Gap end");
    gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

    addExportPopupMenu(diff, cp);

    return cp;
}

From source file:be.vds.jtbdive.client.view.core.stats.StatChartGenerator.java

private static JFreeChart buildChartForDive(StatQueryObject sqo) {
    Collection<StatSerie> s = sqo.getValues();
    String legend = I18nResourceManager.sharedInstance().getString("dive.times");
    TimeSeriesCollection collection = new TimeSeriesCollection();
    for (StatSerie statSerie : s) {
        TimeSeries ts = new TimeSeries(legend);
        for (StatPoint point : statSerie.getPoints()) {
            Date dd = (Date) point.getX();
            FixedMillisecond day = new FixedMillisecond(dd);
            Object index = ts.getDataItem(day);
            if (null != index) {
                GregorianCalendar gc = new GregorianCalendar();
                gc.setTime(dd);//w  w w.  j a  va2s.co  m
                gc.add(Calendar.MILLISECOND, 1);
                day = new FixedMillisecond(gc.getTime());
            }

            if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DEPTHS)) {
                ts.add(day, UnitsAgent.getInstance().convertLengthFromModel((Double) point.getY()));
            } else if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.TEMPERATURES)) {
                ts.add(day, UnitsAgent.getInstance().convertTemperatureFromModel((Double) point.getY()));
            } else {
                ts.add(day, point.getY());
            }
        }
        collection.addSeries(ts);
    }

    JFreeChart chart = createLineChart(collection, getXLabel(sqo), getYLabel(sqo));

    if (sqo.getStatYAxisParams().getStatYAxis().equals(StatYAxis.DIVE_TIME)) {
        XYPlot xyp = (XYPlot) chart.getPlot();
        ((NumberAxis) xyp.getRangeAxis()).setNumberFormatOverride(new HoursMinutesNumberFormat());
    }

    return chart;
}

From source file:org.jfree.chart.demo.selection.SelectionDemo4.java

/**
 * Creates a chart.//from w w w .ja  va 2s.  c om
 * 
 * @param dataset  a dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setDefaultOutlinePaint(Color.red);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset(1, 1.0D);
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "This chart shows various combinations of the useFillPaint and useOutlinePaint flags.");
    texttitle.setFont(new Font("Dialog", 0, 10));
    jfreechart.addSubtitle(texttitle);//from  w  ww .  j  a  va 2 s  .  c  o  m
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setSeriesShape(0, double1);
    xylineandshaperenderer.setSeriesPaint(0, Color.red);
    xylineandshaperenderer.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.gray);
    XYDataset xydataset1 = createDataset(2, 2D);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xylineandshaperenderer1.setSeriesShape(0, double1);
    xylineandshaperenderer1.setSeriesPaint(0, Color.red);
    xylineandshaperenderer1.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer1.setUseFillPaint(true);
    XYDataset xydataset2 = createDataset(3, 3D);
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    xyplot.setDataset(2, xydataset2);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xylineandshaperenderer2.setSeriesShape(0, double1);
    xylineandshaperenderer2.setSeriesPaint(0, Color.red);
    xylineandshaperenderer2.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer2.setUseOutlinePaint(true);
    XYDataset xydataset3 = createDataset(4, 4D);
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xyplot.setDataset(3, xydataset3);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    xylineandshaperenderer3.setSeriesShape(0, double1);
    xylineandshaperenderer3.setSeriesPaint(0, Color.red);
    xylineandshaperenderer3.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer3.setUseOutlinePaint(true);
    xylineandshaperenderer3.setUseFillPaint(true);
    XYDataset xydataset4 = createDataset(5, 5D);
    XYLineAndShapeRenderer xylineandshaperenderer4 = new XYLineAndShapeRenderer();
    xyplot.setDataset(4, xydataset4);
    xyplot.setRenderer(4, xylineandshaperenderer4);
    xylineandshaperenderer4.setSeriesShape(0, double1);
    xylineandshaperenderer4.setSeriesPaint(0, Color.red);
    xylineandshaperenderer4.setSeriesFillPaint(0, Color.yellow);
    xylineandshaperenderer4.setSeriesOutlinePaint(0, Color.gray);
    xylineandshaperenderer4.setUseOutlinePaint(true);
    xylineandshaperenderer4.setUseFillPaint(true);
    xylineandshaperenderer4.setDrawOutlines(false);
    return jfreechart;
}

From source file:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a chart.//  w  w  w  .  j a v  a2s.  co  m
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return The chart.
 */
private static JFreeChart createChart(IntervalXYDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createHistogram("SelectionDemo4", null, null, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlinePaint(Color.red);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(renderer, ext, Color.white);

    //register plot as selection change listener
    ext.addSelectionChangeListener(plot);

    return chart;
}

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

private static JFreeChart createChart(OHLCDataset ohlcdataset) {
    JFreeChart jfreechart = ChartFactory.createCandlestickChart("Candlestick Demo 1", "Time", "Value",
            ohlcdataset, true);/*from  ww w . j  a  va2s .c om*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setLowerMargin(0.0D);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart("XYAreaRenderer2Demo1", "Domain (X)", "Range (Y)",
            xydataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(new XYAreaRenderer2());
    xyplot.setForegroundAlpha(0.65F);// www.ja  v a  2  s.  co m
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setTickMarkPaint(Color.black);
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    valueaxis1.setTickMarkPaint(Color.black);
    return jfreechart;
}