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:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel//from   ww w  .  jav  a  2  s .c o  m
 * @param x1
 * @param y1
 * @return
 */
public static AffineTransform getModelToViewTransformXY(ChartPanel chartPanel, double x1, double y1) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof XYPlot) {
        XYPlot xyp = (XYPlot) plot;
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().valueToJava2D(x1, dataArea, xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y1, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

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

/**
 * Creates a chart.//from   w  ww. j  ava  2  s. c o  m
 * 
 * @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.setDefaultShapesVisible(true);
        renderer.setDefaultShapesFilled(true);
    }

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

    return chart;

}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("US$ Treasury Yields", "Date", "Yield",
            xydataset, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    GregorianCalendar gregoriancalendar = new GregorianCalendar(2005, 10, 15);
    xyplot.setDomainAxis(new CustomDateAxis("Date", gregoriancalendar.getTime()));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*from  w  ww  .  ja  v a2 s.c o  m*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    jfreechart.addSubtitle(new TextTitle("November 2005"));
    TextTitle texttitle = new TextTitle("Source: http://www.econstats.com/r/r_am1.htm");
    texttitle.setFont(new Font("Dialog", 0, 9));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date",
            "Price Per Unit", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
    }/*from  ww w  . j a  v  a  2 s. com*/
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    return jfreechart;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the axis-related properties of a chart.
 * /*from  ww  w .j  av  a  2s .c  o  m*/
 * @param aControl
 *            Chart control to be updated.
 * @param aAxes
 *            Axis-related visual settings to be applied.
 * @param aGrid
 *            Grid-related visual settings to be applied.
 */
public static void updateAxes(JFreeChart aControl, AxesSettings aAxes, GridSettings aGrid) {
    XYPlot plot = aControl.getXYPlot();
    Range domainDataRange = aAxes.getLogarithmicDomainAxis()
            ? new Range(logLowerBound(plot.getDataset(), true),
                    plot.getDataRange(plot.getDomainAxis()).getUpperBound())
            : plot.getDataRange(plot.getDomainAxis());
    Range rangeDataRange = aAxes.getLogarithmicRangeAxis()
            ? new Range(logLowerBound(plot.getDataset(), false),
                    plot.getDataRange(plot.getRangeAxis()).getUpperBound())
            : plot.getDataRange(plot.getRangeAxis());
    updateAxes(plot, aAxes, aGrid, domainDataRange, rangeDataRange);
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

private static void decorateCategoryPlot(JFreeChart chart) {

    XYPlot plot = chart.getXYPlot();
    XYItemRenderer render = plot.getRenderer();
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis valueAxis = plot.getRangeAxis();

    Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE); //$NON-NLS-1$

    render.setBaseItemLabelFont(font);//www.j  a va  2  s .c o  m
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE); //$NON-NLS-1$
    domainAxis.setLabelFont(font);
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE); //$NON-NLS-1$
    valueAxis.setLabelFont(font);
    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE); //$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);
    font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE); //$NON-NLS-1$
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setItemFont(font);
    }
    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE); //$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }
    font = null;
    if (render instanceof BarRenderer) {
        int rowCount = chart.getCategoryPlot().getDataset().getRowCount();
        domainAxis.setUpperMargin(0.1);
        // domainAxis.setMaximumCategoryLabelLines(10);
        ((BarRenderer) render).setItemMargin(-0.40 * rowCount);
    }
    // set color
    int rowCount = chart.getXYPlot().getDataset().getSeriesCount();
    for (int i = 0; i < rowCount; i++) {
        plot.getRenderer().setSeriesPaint(i, Color.RED);
    }

}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Creates a scatter plot that visualizes the given data collection.
 * /* ww  w .ja v a 2  s  .c  om*/
 * @param aCollection
 *            Data to be visualized.
 * @param aGeneral
 *            General visual settings to be applied.
 * @param aAxes
 *            Axis-related visual settings to be applied.
 * @param aGrid
 *            Grid-related visual settings to be applied.
 * @param aScatter
 *            Point-related visual settings to be applied.
 * @return Newly created chart control.
 */
private static JFreeChart createScatter(XYSeriesCollection aCollection, GeneralVisSettings aGeneral,
        AxesSettings aAxes, GridSettings aGrid, ScatterSettings aScatter) {

    JFreeChart chart = ChartFactory.createScatterPlot(null, // title
            convertLabel(aAxes.getDomainAxisLabel()), // label of X axis
            convertLabel(aAxes.getRangeAxisLabel()), // label of Y axis
            aCollection, // dataset
            PlotOrientation.VERTICAL, // orientation
            false, // create legend
            true, // display tooltips
            false); // generate urls
    XYPlot plot = chart.getXYPlot();
    Range domainDataRange = aAxes.getLogarithmicDomainAxis()
            ? new Range(logLowerBound(plot.getDataset(), true),
                    plot.getDataRange(plot.getDomainAxis()).getUpperBound())
            : plot.getDataRange(plot.getDomainAxis());
    Range rangeDataRange = aAxes.getLogarithmicRangeAxis()
            ? new Range(logLowerBound(plot.getDataset(), false),
                    plot.getDataRange(plot.getRangeAxis()).getUpperBound())
            : plot.getDataRange(plot.getRangeAxis());
    updateGeneral(plot, aGeneral);
    updateAxes(plot, aAxes, aGrid, domainDataRange, rangeDataRange);
    updateScatter(plot, aScatter);
    chart.setBackgroundPaint(null);
    return chart;
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Calculate and update the Domain Offset Crosshair and draw the crosshair on the XYPlot.
 * Return the value set on the XYPlot, or Double.MIN_VALUE on failure.
 *
 * @param chartui//from  w w  w  .j  av  a  2  s .c om
 * @param valueminimum
 * @param valuemaximum
 * @param offset
 * @param debug
 *
 * @return double
 */

public static double updateDomainCrosshairForOffsetControl(final ChartUIComponentPlugin chartui,
        final int valueminimum, final int valuemaximum, final double offset, final boolean debug) {
    final String SOURCE = "ChartHelper.updateDomainCrosshairForOffsetControl() ";
    double dblDomainCrosshairXYPlot;

    dblDomainCrosshairXYPlot = Double.MIN_VALUE;

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

            //  Save the supplied new value
            chartui.setDomainCrosshair(offset);

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

            if (offset >= 0) {
                //dblPositionFraction = (offset - (double)valueminimum) / (double)(valuemaximum - valueminimum);
                dblPositionFraction = (offset * 2.0) / (double) (valuemaximum - valueminimum);
            } else {
                dblPositionFraction = 0.0;
            }

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

            // Update the XYPlot
            plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot);

            FrameworkSingletons.LOGGER.debug(debug,
                    SOURCE + "Domain Crosshair updated [value.knob=" + offset + "] [value.xyplot="
                            + dblDomainCrosshairXYPlot + "] [domain.lowerbound=" + domainAxis.getLowerBound()
                            + "] [domain.upperbound=" + domainAxis.getUpperBound() + "] [value.fraction="
                            + dblPositionFraction + "] [value.minimum=" + valueminimum + "] [value.maximum="
                            + valuemaximum + "]");
        } else {
            FrameworkSingletons.LOGGER.debug(debug,
                    SOURCE + "There is no Chart, so cannot update Domain Crosshair on XYPlot");

            // Save a default value
            chartui.setDomainCrosshair(valueminimum);

            dblDomainCrosshairXYPlot = Double.MIN_VALUE;
        }
    }

    return (dblDomainCrosshairXYPlot);
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of two Area Diagrams.
 * /*  w  ww .  j  a  va  2 s .  c  o  m*/
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param doubles
 *          The array of values of the first array.
 * 
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createExpectedPowerChart(String title, String x, String y, double[] data) {
    JFreeChart chart = null;

    XYSeries series1 = new XYSeries("Expected Power");
    for (int i = 0; i < data.length; i++) {
        series1.add(i, data[i]);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;

    chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, 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);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setRange(0.0, 1440.0);
    domainAxis.setTickUnit(new NumberTickUnit(100));

    return new ChartPanel(chart);
}

From source file:bullioneconomy.bullionchart.java

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

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Gold Price in Recent Years", // title
            "Date", // x-axis label
            "Price Per 10g", // 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.setDefaultShapesVisible(true);
        //renderer.setDefaultShapesFilled(true);
    }

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

    return chart;

}