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

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

Introduction

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

Prototype

public void setRangeAxis(int index, ValueAxis axis) 

Source Link

Document

Sets a range axis and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.spotify.heroic.http.render.RenderUtils.java

private static JFreeChart buildChart(final String title, final XYDataset lineAndShape, final XYDataset interval,
        final XYItemRenderer lineAndShapeRenderer, final XYItemRenderer intervalRenderer) {
    final ValueAxis timeAxis = new DateAxis();
    timeAxis.setLowerMargin(0.02);//from   ww w.  ja v  a  2  s . c  o  m
    timeAxis.setUpperMargin(0.02);

    final NumberAxis valueAxis = new NumberAxis();
    valueAxis.setAutoRangeIncludesZero(false);

    final XYPlot plot = new XYPlot();

    plot.setDomainAxis(0, timeAxis);
    plot.setRangeAxis(0, valueAxis);

    plot.setDataset(0, lineAndShape);
    plot.setRenderer(0, lineAndShapeRenderer);

    plot.setDomainAxis(1, timeAxis);
    plot.setRangeAxis(1, valueAxis);

    plot.setDataset(1, interval);
    plot.setRenderer(1, intervalRenderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
}

From source file:ta4jexamples.analysis.CashFlowToChart.java

/**
 * Adds the cash flow axis to the plot./*from   w w w.  java  2  s  . c o  m*/
 * @param plot the plot
 * @param dataset the cash flow dataset
 */
private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) {
    final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio");
    cashAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, cashAxis);
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer();
    cashFlowRenderer.setSeriesPaint(0, Color.blue);
    plot.setRenderer(1, cashFlowRenderer);
}

From source file:com.leonarduk.finance.analysis.CashFlowToChart.java

/**
 * Adds the cash flow axis to the plot.//from w  w  w  .j  a  v  a 2s  .  com
 *
 * @param plot
 *            the plot
 * @param dataset
 *            the cash flow dataset
 */
private static void addCashFlowAxis(final XYPlot plot, final TimeSeriesCollection dataset) {
    final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio");
    cashAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, cashAxis);
    plot.setDataset(1, dataset);
    plot.mapDatasetToRangeAxis(1, 1);
    final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer();
    cashFlowRenderer.setSeriesPaint(0, Color.blue);
    plot.setRenderer(1, cashFlowRenderer);
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) {
    ValueAxis axis = null;//from   www  . j  av  a  2s  .c o m
    if (chartAxisData.getType() != null) {
        if (chartAxisData.getType().equals("number"))
            axis = createNumberAxis(chart, chartAxisData);
        else if (chartAxisData.getType().equals("date"))
            axis = createDateAxis(chart, chartAxisData);

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }

        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());
        axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels());
    }

    XYPlot plot = chart.getXYPlot();
    if (chartAxisData.isDomain()) {
        plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis);
    } else {
        plot.setRangeAxis(axisIndex, axis);
        XYDataset dataset = (XYDataset) chartAxisData.getDatasource();
        plot.setRenderer(axisIndex, new StandardXYItemRenderer());
        plot.setDataset(axisIndex, dataset);
        plot.mapDatasetToRangeAxis(axisIndex, axisIndex);
    }

    setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex));
}

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Generates a plot for comparing to datasets
 * @param title the name of the plot//from w w w  .j  a va  2 s.co m
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 * @return a chart object for displaying or saving as picture
 */
public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Input Value", // y-axis label
            dataset1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    XYPlot plot = chart.getXYPlot();

    Axis axis1 = plot.getRangeAxis(0);
    axis1.setLabelPaint(Color.red);

    NumberAxis axis2 = new NumberAxis("Twitter");
    axis2.setLabelPaint(Color.blue);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, renderer);

    return chart;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);/* w  ww . ja va2  s  .  c  o  m*/
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static JFreeChart createTimeSeriesChart() {
    XYDataset dataset1 = createDataset1();
    //DomainAxis//from  www  .  j ava2  s  .c o m
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    NumberAxis valueAxis2 = new NumberAxis("");
    valueAxis2.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    XYDataset dataset2 = createDataset2();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    //Plot
    XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, valueAxis2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setBackgroundPaint(plotBackgroundPaint);
    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);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    valueAxis.setAutoRange(false);
    timeAxis.setAutoRange(false);
    return chart;
}

From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java

private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx,
        final TimeSeriesCollection tsDataset, final JFreeChart tsChart) {
    final int numInstances = dataSet.numInstances();

    int axisNumber = 0;
    final Calendar cal = Calendar.getInstance();
    for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) {
        final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name());
        for (int k = 0; k < numInstances; k++) {
            final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx);
            cal.setTimeInMillis(timeInMilliSec);
            if (dataSet.instance(k).isMissing(i)) {
                ts.addOrUpdate(new Millisecond(cal.getTime()), null);
            } else {
                ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i));
            }// w  w w. j av  a  2  s .  c  om
        }
        if (!ts.isEmpty()) {
            if (axisNumber == 0) {
                tsDataset.addSeries(ts);
            } else {
                final XYPlot plot = tsChart.getXYPlot();
                final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name());
                axisToAdd.setAutoRangeIncludesZero(false);
                plot.setRangeAxis(axisNumber, axisToAdd);
                final TimeSeriesCollection t = new TimeSeriesCollection();
                t.addSeries(ts);
                plot.setDataset(axisNumber, t);
                plot.mapDatasetToRangeAxis(axisNumber, axisNumber);
                final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
                renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name()));
                plot.setRenderer(axisNumber, renderer2);
            }
            axisNumber++;
        }
    }
}

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

private static JFreeChart createChart(OHLCDataset ohlcdataset) {
    JFreeChart jfreechart = ChartFactory.createHighLowChart("OHLC Demo 3", "Time", "Price", ohlcdataset, true);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    HighLowRenderer highlowrenderer = (HighLowRenderer) xyplot.getRenderer();
    highlowrenderer.setBaseStroke(new BasicStroke(2.0F));
    highlowrenderer.setSeriesPaint(0, Color.blue);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Price 2");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.setRenderer(1, new CandlestickRenderer(10D));
    xyplot.mapDatasetToRangeAxis(1, 1);/*from  w w  w .j  av a2s .com*/
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

private static JFreeChart priceVolumeHistoryChart(String title, TimePeriodValuesCollection prices,
        TimePeriodValuesCollection volumes, boolean scalePrices) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, null, "Price", prices, false, false, false);
    XYPlot plot = chart.getXYPlot();
    if (scalePrices) {
        setBoundsForPrice(chart);/*from   w  w w .j a  v  a  2s  .  c  o m*/
    } else {
        setBoundsForPercent(chart);
    }

    NumberAxis rangeAxis2 = new NumberAxis("Volume");
    rangeAxis2.setUpperMargin(2);
    plot.setRangeAxis(1, rangeAxis2);
    plot.setDataset(1, volumes);
    plot.mapDatasetToRangeAxis(1, 1);
    XYBarRenderer renderer2 = new XYBarRenderer(0.2);
    plot.setRenderer(1, renderer2);
    return chart;
}