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:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Update the Domain Slider Crosshair./*from w w  w.j  a  va 2 s. co  m*/
 *
 * @param chartui
 * @param movingindex
 * @param domainstart
 * @param domainend
 * @param movingslidervalue
 * @param sliderminimum
 * @param slidermaximum     *
 * @param debug
 *
 * @return double
 */

public static double updateDomainCrosshairForDomainSlider(final ChartUIComponentPlugin chartui,
        final int movingindex, final int domainstart, final int domainend, final int movingslidervalue,
        final int sliderminimum, final int slidermaximum, final boolean debug) {
    final String SOURCE = "ChartHelper.updateDomainCrosshairForDomainSlider() ";
    final double dblDomainCrosshairXYPlot;

    if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null)
            && (chartui.getChartPanel().getChart().getPlot() != null)) {
        final double dblDomainCrosshair;
        final double dblPositionFraction;
        final XYPlot plot;
        final ValueAxis domainAxis;
        final Range range;

        plot = (XYPlot) chartui.getChartPanel().getChart().getPlot();
        domainAxis = plot.getDomainAxis();
        range = domainAxis.getRange();

        if (movingindex == INDEX_LEFT) {
            // Trying to Move Left, but are we already at the Left Extent?
            if (movingslidervalue <= sliderminimum) {
                dblDomainCrosshair = sliderminimum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "At Left Extent, cannot move Left Thumb to the Left" + "  [crosshair.domain="
                                + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
            // It is Ok to move further Left than the current setting of domainstart,
            // but we musn't draw a crosshair
            else if (movingslidervalue < domainstart) {
                // Do not draw a crosshair, set to lower bound?
                dblDomainCrosshair = sliderminimum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Left Thumb to the Left beyond current DomainStart"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            } else {
                // Try to Move Right, the slider won't be able to move past the Right Thumb
                dblDomainCrosshair = movingslidervalue;

                dblPositionFraction = (double) (movingslidervalue - domainstart)
                        / (double) (domainend - domainstart);
                dblDomainCrosshairXYPlot = domainAxis.getLowerBound()
                        + (dblPositionFraction * range.getLength());

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Left Thumb to the Right" + "  [crosshair.domain=" + dblDomainCrosshair
                                + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
        } else if (movingindex == INDEX_RIGHT) {
            //  Trying to Move Right, but are we already at the Right Extent?
            if (movingslidervalue >= slidermaximum) {
                dblDomainCrosshair = slidermaximum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "At Right Extent, cannot move Right Thumb to the Right"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            }
            // It is Ok to move further Right than the current setting of domainend
            // but we musn't draw a crosshair
            else if (movingslidervalue > domainend) {
                // Do not draw a crosshair, set to upper bound?
                dblDomainCrosshair = slidermaximum;

                dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength();

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Right Thumb to the Right beyond current DomainEnd"
                                + "  [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot"
                                + dblDomainCrosshairXYPlot + "]");
            } else {
                // Try to Move Left, the slider won't be able to move past the Left Thumb
                dblDomainCrosshair = movingslidervalue;

                dblPositionFraction = (double) (movingslidervalue - domainstart)
                        / (double) (domainend - domainstart);
                dblDomainCrosshairXYPlot = domainAxis.getLowerBound()
                        + (dblPositionFraction * range.getLength());

                FrameworkSingletons.LOGGER.debug(debug,
                        SOURCE + "Moving Right Thumb to the Left" + "  [crosshair.domain=" + dblDomainCrosshair
                                + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
            }
        } else {
            // Do nothing, an Error
            dblDomainCrosshair = sliderminimum;
            dblDomainCrosshairXYPlot = domainAxis.getLowerBound();

            FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Invalid Thumb index" + "  [crosshair.domain="
                    + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
        }

        chartui.setDomainCrosshair(dblDomainCrosshair);
        plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);
    } else {
        chartui.setDomainCrosshair(sliderminimum);
        dblDomainCrosshairXYPlot = Double.MIN_VALUE;

        FrameworkSingletons.LOGGER.debug(debug,
                SOURCE + "There is no Chart, so cannot update Domain Slider Crosshair" + "  [crosshair.domain="
                        + sliderminimum + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]");
    }

    return (dblDomainCrosshairXYPlot);
}

From source file:Data.java

/**
 * Creates a chart.//from w  w  w.  j  a v  a 2  s .  c  o  m
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Graphique des tempratures et humidits", // title
            "Date", // x-axis label
            "Temperture/Humidit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("d.M.yy HH:mm:ss"));

    return chart;

}

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection tempChrData, boolean showlables) {
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesVisibleInLegend(0, showlables);
    renderer.setSeriesVisibleInLegend(1, showlables);
    //renderer.setBaseShape(new Ellipse2D.Float(0, 0, 2,2), false);

    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);//from   w  w  w .  ja  v  a 2s.c  o m
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setAutoRangeMinimumSize(0.0000005);
        rangeAxis.setLowerBound(1d);
        //rangeAxis.setAutoRangeIncludesZero(false);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", tempChrData,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    final Marker thresholdLine = new ValueMarker(0.0000005);
    thresholdLine.setPaint(Color.red);
    if (showlables) {
        thresholdLine.setLabel("P = 510??");
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(false);
    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    chrAxis.setAutoRangeIncludesZero(false);
    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:com.alibaba.dubbo.monitor.simple.SimpleMonitorService.java

private static void createChart(String key, String service, String method, String date, String[] types,
        Map<String, long[]> data, double[] summary, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
    DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
    TimeSeriesCollection xydataset = new TimeSeriesCollection();
    for (int i = 0; i < types.length; i++) {
        String type = types[i];//ww  w.j  a v  a 2s. c o m
        TimeSeries timeseries = new TimeSeries(type);
        for (Map.Entry<String, long[]> entry : data.entrySet()) {
            try {
                timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            }
        }
        xydataset.addSeries(timeseries);
    }
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
            "max: " + numberFormat.format(summary[0])
                    + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: "
                    + numberFormat.format(summary[2])
                    + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""),
            toDisplayService(service) + "  " + method + "  " + toDisplayDate(date), key, xydataset, true, true,
            false);
    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setRangeGridlinePaint(Color.GRAY);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    BufferedImage image = jfreechart.createBufferedImage(600, 300);
    try {
        if (logger.isInfoEnabled()) {
            logger.info("write chart: " + path);
        }
        File methodChartFile = new File(path);
        File methodChartDir = methodChartFile.getParentFile();
        if (methodChartDir != null && !methodChartDir.exists()) {
            methodChartDir.mkdirs();
        }
        FileOutputStream output = new FileOutputStream(methodChartFile);
        try {
            ImageIO.write(image, "png", output);
            output.flush();
        } finally {
            output.close();
        }
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
    }
}

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

/**
 * //from ww  w. ja v  a  2 s .c om
 * @param myChart
 * @return Range the domainAxis zoom (X-axis)
 */
public static Range getZoomDomainAxis(ChartViewer myChart) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();

    return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound());
}

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

/**
 * Apply an absolute offset to domain (x) axis and move it
 * //from w  ww  .  j av a2s  .c om
 * @param myChart
 * @param xoffset
 * @param autoRangeY
 */
public static void offsetDomainAxisAbsolute(ChartViewer myChart, double xoffset, boolean autoRangeY) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    // apply offset on x

    Range range = new Range(domainAxis.getLowerBound() + xoffset, domainAxis.getUpperBound() + xoffset);
    setZoomDomainAxis(myChart, keepRangeWithinAutoBounds(domainAxis, range), autoRangeY);
}

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

/**
 * Zoom into a chart panel/*from w w  w.  j  a  va 2 s  . c  o  m*/
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void setZoomDomainAxis(ChartViewer myChart, Range zoom, boolean autoRangeY) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    setZoomAxis(domainAxis, keepRangeWithinAutoBounds(domainAxis, zoom));

    if (autoRangeY) {
        autoRangeAxis(myChart);
    }
}

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

/**
 * Move a chart by a percentage x-offset if xoffset is <0 the shift will be negativ (xoffset>0
 * results in a positive shift)//from  www .  j ava2  s . c o m
 * 
 * @param myChart
 * @param xoffset in percent
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void offsetDomainAxis(ChartViewer myChart, double xoffset, boolean autoRangeY) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    // apply offset on x
    double distance = (domainAxis.getUpperBound() - domainAxis.getLowerBound()) * xoffset;

    Range range = new Range(domainAxis.getLowerBound() + distance, domainAxis.getUpperBound() + distance);
    setZoomDomainAxis(myChart, keepRangeWithinAutoBounds(domainAxis, range), autoRangeY);
}

From source file:cit.workflow.engine.manager.test.SWTTimeSeriesDemo.java

/**
 * Creates a chart.//www . j a va 2 s . c  om
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

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

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}

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

/**
 * Calculates the size of a chart for a given fixed plot width Domain and Range axes need to share
 * the same unit (e.g. mm)//from   w ww .ja  v a  2  s . c om
 * 
 * @param chart
 * @param plotWidth
 * @return
 */
public static Dimension calcSizeForPlotWidth(ChartViewer myChart, double plotWidth, int iterations) {
    // ranges
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    Range x = domainAxis.getRange();
    ValueAxis rangeAxis = plot.getRangeAxis();
    Range y = rangeAxis.getRange();

    // plot height is fixed
    double plotHeight = plotWidth / x.getLength() * y.getLength();
    return calcSizeForPlotSize(myChart, plotWidth, plotHeight, iterations);
}