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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

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

public static void main(String args[]) {
    XYSeries xyseries = new XYSeries("Advisory Range");
    xyseries.add(new Integer(1200), new Integer(1));
    xyseries.add(new Integer(1500), new Integer(1));
    XYSeries xyseries1 = new XYSeries("Normal Range");
    xyseries1.add(new Integer(2000), new Integer(4));
    xyseries1.add(new Integer(2300), new Integer(4));
    XYSeries xyseries2 = new XYSeries("Recommended");
    xyseries2.add(new Integer(2100), new Integer(2));
    XYSeries xyseries3 = new XYSeries("Current");
    xyseries3.add(new Integer(2400), new Integer(3));
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(xyseries1);
    xyseriescollection.addSeries(xyseries2);
    xyseriescollection.addSeries(xyseries3);
    JFreeChart jfreechart = ChartFactory.createXYLineChart("My Chart", "Calories", "Y", xyseriescollection,
            PlotOrientation.VERTICAL, true, true, false);
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3, null);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(standardxyitemrenderer);
    ValueAxis valueaxis = xyplot.getRangeAxis();
    valueaxis.setTickLabelsVisible(false);
    valueaxis.setRange(0.0D, 5D);/* w  ww . jav  a2 s.  c  om*/
    ChartFrame chartframe = new ChartFrame("Test", jfreechart);
    chartframe.pack();
    chartframe.setVisible(true);
}

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

/**
 * Starting point for the demo.//from   w  ww. ja va  2 s  .c o m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create some data...
    final XYSeries series1 = new XYSeries("Advisory Range");
    series1.add(new Integer(1200), new Integer(1));
    series1.add(new Integer(1500), new Integer(1));

    final XYSeries series2 = new XYSeries("Normal Range");
    series2.add(new Integer(2000), new Integer(4));
    series2.add(new Integer(2300), new Integer(4));

    final XYSeries series3 = new XYSeries("Recommended");
    series3.add(new Integer(2100), new Integer(2));

    final XYSeries series4 = new XYSeries("Current");
    series4.add(new Integer(2400), new Integer(3));

    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series1);
    data.addSeries(series2);
    data.addSeries(series3);
    data.addSeries(series4);

    // create a chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("My Chart", "Calories", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES, null);
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(renderer);
    final ValueAxis axis = plot.getRangeAxis();
    axis.setTickLabelsVisible(false);
    axis.setRange(0.0, 5.0);

    // create and display a frame...
    final ChartFrame frame = new ChartFrame("Test", chart);
    frame.pack();
    frame.setVisible(true);

}

From source file:ta4jexamples.indicators.CandlestickChart.java

public static void main(String[] args) {
    /**/*from ww w  . j av  a2 s .c o  m*/
     * Getting time series
     */
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();

    /**
     * Creating the OHLC dataset
     */
    OHLCDataset ohlcDataset = createOHLCDataset(series);

    /**
     * Creating the additional dataset
     */
    TimeSeriesCollection xyDataset = createAdditionalDataset(series);

    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset,
            true);
    // Candlestick rendering
    CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    /**
     * Displaying the chart
     */
    displayChart(chart);
}

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

/**
 * Starting point for the demo.//from w ww  .  j  a  va2  s .co m
 *
 * @param args  ignored.
 *
 * @throws ParseException if there is a problem parsing dates.
 */
public static void main(final String[] args) throws ParseException {

    //  Create a sample dataset
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    final XYSeries dataSeries = new XYSeries("Curve data");
    final ArrayList toolTips = new ArrayList();
    dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22);
    toolTips.add("1D - 5.22");
    dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18);
    toolTips.add("2D - 5.18");
    dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23);
    toolTips.add("3D - 5.23");
    dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15);
    toolTips.add("4D - 5.15");
    dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22);
    toolTips.add("5D - 5.22");
    dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25);
    toolTips.add("6D - 5.25");
    dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31);
    toolTips.add("7D - 5.31");
    dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36);
    toolTips.add("8D - 5.36");
    final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
    final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator();
    ttg.addToolTipSeries(toolTips);

    //  Create the chart
    final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp");
    final ValueAxis timeAxis = new DateAxis("");
    final NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null);
    final StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
            StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg);
    sxyir.setShapesFilled(true);
    plot.setRenderer(sxyir);
    final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("xychart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("xychart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"xychart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return;
}

From source file:PowerMethod.power_method.java

public static void main(String[] args) {
    //////////////////////////////////////////////////////
    // Edit vals to contain values for matrix A         //
    // Edit vals2 to contain values for initial vector  //
    //////////////////////////////////////////////////////
    double[][] vals = { { 3, 4 }, { 3, 1 } };
    RealMatrix A = new Array2DRowRealMatrix(vals);
    double[][] vals2 = { { 1 }, { 1 } };
    RealMatrix u = new Array2DRowRealMatrix(vals2);
    power_object a = power_method(A, u, .1, 7);

    List<RealMatrix> matrices = genMatrices();
    List<trace_det> trace_dets = new ArrayList<>();
    double trace;
    double det;/*from ww w  .java2 s. co  m*/
    int iterA;
    int iterInverseA;
    for (RealMatrix r : matrices) {
        MatrixMethods m = new MatrixMethods(r);
        RealMatrix inverseR = m.inverseMatrix();
        power_object largestVal = power_method(r, u, .00005, 100);
        power_object smallestVal = power_method(inverseR, u, .00005, 100);
        if (largestVal == null || smallestVal == null) {
            continue;
        }
        trace = m.trace();
        det = m.determinant();
        iterA = largestVal.getNumN();
        iterInverseA = smallestVal.getNumN();
        trace_det td = new trace_det(trace, det, iterA, iterInverseA);
        trace_dets.add(td);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant",
            "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesPaint(3, Color.BLACK);
    renderer.setSeriesPaint(4, Color.YELLOW);
    renderer.setSeriesPaint(5, Color.PINK);
    renderer.setSeriesPaint(6, Color.ORANGE);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.MAGENTA);
    renderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    renderer.setSeriesPaint(10, Color.DARK_GRAY);
    //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) );
    //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) );
    plot.setRenderer(renderer);
    ChartFrame frame = new ChartFrame("Power Method", chart);
    frame.pack();
    frame.setVisible(true);

    JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method",
            "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel inverseChartPanel = new ChartPanel(inverseChart);
    inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot inversePlot = inverseChart.getXYPlot();
    XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer();
    inverseRenderer.setSeriesPaint(0, Color.RED);
    inverseRenderer.setSeriesPaint(1, Color.BLUE);
    inverseRenderer.setSeriesPaint(2, Color.GREEN);
    inverseRenderer.setSeriesPaint(3, Color.BLACK);
    inverseRenderer.setSeriesPaint(4, Color.YELLOW);
    inverseRenderer.setSeriesPaint(5, Color.PINK);
    inverseRenderer.setSeriesPaint(6, Color.ORANGE);
    inverseRenderer.setSeriesPaint(7, Color.GRAY);
    inverseRenderer.setSeriesPaint(8, Color.MAGENTA);
    inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY);
    inversePlot.setRenderer(renderer);
    ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart);
    inverseFrame.pack();
    inverseFrame.setVisible(true);
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("Bubble Chart Demo 2", "X", "Y", xyzdataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(new XYBubbleRenderer(0));
    xyplot.setForegroundAlpha(0.65F);/*  ww  w.j ava 2  s  . co  m*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    xyitemrenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    xyitemrenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    xyitemrenderer.setBaseItemLabelsVisible(true);
    xyitemrenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setRange(0.0D, 10D);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setRange(0.0D, 10D);
    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);//from ww w. j  av  a  2s  . 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;
}

From source file:evaluation.simulator.gui.results.LineJFreeChartCreator.java

/**
 * Creates a chart./*www .  j a  v a2s.c om*/
 * 
 * @param dataset
 *            the data for the chart.
 * 
 * @return a chart.
 */
private static JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Latency Mix Message", // chart title
            "BATCH_SIZE", // x axis label
            "ms", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // Spezial berschreiben des Aussehen der Striche im Graphen
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
        private static final long serialVersionUID = 1L;
        Stroke soild = new BasicStroke(2.0f);

        @Override
        public Stroke getItemStroke(int row, int column) {
            return this.soild;
        }
    };

    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);

    return chart;

}

From source file:com.leonarduk.finance.chart.CandlestickChart.java

public static void displayCandlestickChart(final Stock stock) throws IOException {
    final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1);

    /**/*from w ww  .  j  a v a 2  s.  c  o  m*/
     * Creating the OHLC dataset
     */
    final OHLCDataset ohlcDataset = CandlestickChart.createOHLCDataset(series);

    /**
     * Creating the additional dataset
     */
    final TimeSeriesCollection xyDataset = CandlestickChart.createAdditionalDataset(series);

    /**
     * Creating the chart
     */
    final JFreeChart chart = ChartFactory.createCandlestickChart(stock.getName() + " price", "Time",
            stock.getCurrency(), ohlcDataset, true);
    // Candlestick rendering
    final CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    final int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    /**
     * Displaying the chart
     */
    ChartDisplay.displayChartInFrame(chart, 740, 300, "Candlestick Chart");
}

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

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {
    //DomainAxis/*from w  w w.j av  a 2s .  co 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
    //        valueAxis.setAutoRange(false);
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    XYURLGenerator urlGenerator = null;
    //            urlGenerator = new StandardXYURLGenerator();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    //Plot
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    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);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    return chart;
}