Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot XYPlot.

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates a line chart (based on an {@link XYDataset}) with default     
 * settings.    /*from   ww w  .  j  a v  a2s  .  com*/
 *    
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the plot orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return The chart.    
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings./*from w  w w . jav a  2  s. c  o  m*/
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates a stepped XY plot with default settings.    
 *    /* w w  w .  ja  v  a 2 s  .  c  o  m*/
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the plot orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return A chart.    
 */
public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    DateAxis xAxis = new DateAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}

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

private void updateMFI(int days, boolean show) {
    if (this.priceVolumeChart == null) {
        this.priceVolumeChart = this.createPriceVolumeChart(this.priceDataset, this.volumeDataset);
    }/*from  w  w  w  . j  a v a  2s  .  c  o m*/
    if (this.candlestickChart == null) {
        this.candlestickChart = this.createCandlestickChart(this.priceOHLCDataset);
    }

    final TAEx taEx = TAEx.newInstance(TA.MFI, new Integer(days));

    if (show) {
        if (price_volume_ta_map.containsKey(taEx) == false) {
            final XYDataset dataset = org.yccheok.jstock.charting.TechnicalAnalysis.createMFI(this.chartDatas,
                    getMFIKey(days), days);
            NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_MFI"));
            rangeAxis1.setAutoRangeIncludesZero(false); // override default
            rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars
            DecimalFormat format = new DecimalFormat("0");
            rangeAxis1.setNumberFormatOverride(format);

            final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date"));
            timeAxis.setLowerMargin(0.02); // reduce the default margins
            timeAxis.setUpperMargin(0.02);

            XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis1, null);

            XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
            renderer1.setBaseToolTipGenerator(
                    new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#")));
            plot.setRenderer(0, renderer1);
            price_volume_ta_map.put(taEx, plot);
        }

        if (candlestick_ta_map.containsKey(taEx) == false) {
            try {
                /* Not sure why. I cannot make priceVolumeChart and candlestickChart sharing the same
                 * plot. If not, this will inhibit incorrect zooming behavior.
                 */
                candlestick_ta_map.put(taEx, (XYPlot) price_volume_ta_map.get(taEx).clone());
            } catch (CloneNotSupportedException ex) {
                log.error(null, ex);
            }
        }

        if (this.activeTAExs.contains(taEx) == false) {
            // Avoid duplication.
            final XYPlot price_volume_ta = price_volume_ta_map.get(taEx);
            final XYPlot candlestick_ta = candlestick_ta_map.get(taEx);

            final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot();
            final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot();
            if (price_volume_ta != null)
                cplot0.add(price_volume_ta, 1); // weight is 1.
            if (candlestick_ta != null)
                cplot1.add(candlestick_ta, 1); // weight is 1.
            org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.priceVolumeChart);
            org.yccheok.jstock.charting.Utils.applyChartThemeEx(this.candlestickChart);
        }
    } else {
        final CombinedDomainXYPlot cplot0 = (CombinedDomainXYPlot) this.priceVolumeChart.getPlot();
        final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot) this.candlestickChart.getPlot();
        final XYPlot price_volume_ta = price_volume_ta_map.get(taEx);
        final XYPlot candlestick_ta = candlestick_ta_map.get(taEx);

        if (price_volume_ta != null)
            cplot0.remove(price_volume_ta);
        if (candlestick_ta != null)
            cplot1.remove(candlestick_ta);
    }

    if (show && this.activeTAExs.contains(taEx) == false) {
        this.activeTAExs.add(taEx);
        JStock.instance().getChartJDialogOptions().add(taEx);
    } else if (!show) {
        this.activeTAExs.remove(taEx);
        JStock.instance().getChartJDialogOptions().remove(taEx);
    }
}

From source file:com.att.aro.diagnostics.GraphPanel.java

/**
 * Returns a XYPlot for Battery Info// ww  w .  j  a v  a 2s  .  c  o  m
 * 
 * @return XYPlot.
 */
private static XYPlot createBatteryPlot() {

    // Set up renderer
    StandardXYItemRenderer batteryRenderer = new StandardXYItemRenderer(
            StandardXYItemRenderer.SHAPES_AND_LINES);
    batteryRenderer.setAutoPopulateSeriesShape(false);
    batteryRenderer.setBaseShape(DEFAULT_POINT_SHAPE);
    batteryRenderer.setSeriesPaint(0, Color.red);

    // Normalize the throughput axis so that it represents max value
    NumberAxis axis = new NumberAxis();
    axis.setVisible(false);
    axis.setAutoRange(false);
    axis.setRange(0, 110);

    // Create plot
    XYPlot batteryPlot = new XYPlot(null, null, axis, batteryRenderer);
    batteryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    batteryPlot.getRangeAxis().setVisible(false);

    return batteryPlot;

}

From source file:KIDLYFactory.java

/**
 * Creates a stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A chart./*from w  ww  .j a v  a 2s. c  o  m*/
 */
public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    DateAxis xAxis = new DateAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createXYSymbolicAxisChart(String title, XYDataset dataset) {
    SymbolAxis domainAxis = new SymbolAxis("Domain", new String[] { "A", "B", "C", "D" });
    SymbolAxis rangeAxis = new SymbolAxis("Range", new String[] { "V", "X", "Y", "Z" });
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart("SymbolicAxis Demo 1", plot);

    if (lineCondition.indexOf("noshape") != -1)
        renderer.setBaseShapesVisible(false);
    else/*from  w w w  . j  a v a  2 s . c  o m*/
        renderer.setBaseShapesVisible(true);

    if (lineCondition.indexOf("noline") != -1)
        renderer.setBaseLinesVisible(false);

    if (lineCondition.indexOf("nofill") != -1) {
        renderer.setBaseShapesFilled(false);
        renderer.setBaseFillPaint(Color.white);
        renderer.setDrawOutlines(true);
    } else {
        renderer.setBaseShapesFilled(true);
        renderer.setUseFillPaint(false);
    }

    renderer.setUseFillPaint(true);
    //renderer.setFillPaint(Color.white);

    return chart;
}