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.gwaspi.reports.GenericReportGenerator.java

private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background,
        Color backgroundAlternative, Color main) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    // Set dot shape of the currently appended Series
    renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main);
    renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables);
    renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    // Set range axis
    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);/*from w ww .j  av  a 2 s  .  co m*/
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setUpperMargin(0);

        TickUnitSource units = NumberAxis.createIntegerTickUnits();
        rangeAxis.setStandardTickUnits(units);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    // Build subchart
    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC,
            PlotOrientation.VERTICAL, false, false, false);

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

    // CHART BACKGROUD COLOR
    if (combinedPlot.getSubplots().size() % 2 == 0) {
        subplot.setBackgroundPaint(background); // Hue, saturation, brightness
    } else {
        subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness
    }

    // Add significance Threshold to subplot
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to hetzyThreshold
    if (showlables) {
        thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold));
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    // Chromosome Axis Labels
    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setLabelAngle(1.0);
    chrAxis.setAutoRangeIncludesZero(false);
    chrAxis.setAxisLineVisible(true);

    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    //      chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC);
    //      TickUnitSource units = NumberAxis.createIntegerTickUnits();
    //      chrAxis.setStandardTickUnits(units);

    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createStackedAreaChart(String title, XYSeriesCollection areaData,
        XYSeriesCollection lineData, String xLabel, String yLabel, ColorTheme theme) {

    final ValueAxis xAxis = new NumberAxis(xLabel);
    final ValueAxis yAxis = new NumberAxis(yLabel);
    XYPlot mainPlot = new XYPlot();
    mainPlot.setDomainAxis(xAxis);//from  w  w w  .  ja  va 2  s  . c o  m
    mainPlot.setRangeAxis(yAxis);

    mainPlot.setForegroundAlpha(0.9f);

    //[ stacked area
    DefaultTableXYDataset areaDs = new DefaultTableXYDataset();
    for (int i = 0; i < areaData.getSeriesCount(); i++) {
        areaDs.addSeries(areaData.getSeries(i));
    }
    XYItemRenderer stackedRenderer = new StackedXYAreaRenderer2();
    mainPlot.setDataset(areaDs);
    mainPlot.setRenderer(stackedRenderer);

    Color[] colors = generateJetSpectrum(areaData.getSeriesCount());
    for (int i = 0; i < areaData.getSeriesCount(); i++) {
        stackedRenderer.setSeriesPaint(i, colors[i]);
    }
    //]

    //[ lines
    if (lineData != null) {
        XYItemRenderer lineRenderer = new StandardXYItemRenderer();
        DefaultTableXYDataset lineDs = new DefaultTableXYDataset();
        for (int i = 0; i < lineData.getSeriesCount(); i++) {
            lineDs.addSeries(lineData.getSeries(i));
        }
        mainPlot.setDataset(1, lineDs);
        mainPlot.setRenderer(1, lineRenderer);

        colors = new Color[] { Color.black, Color.red, Color.darkGray };
        for (int i = 0; i < lineData.getSeriesCount(); i++) {
            lineRenderer.setSeriesPaint(i, colors[i % colors.length]);
            lineRenderer.setSeriesStroke(i, new BasicStroke(2f));
        }
    }
    //]

    mainPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true);

    formatColorTheme(chart, theme);

    return chart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("DeviationRenderer - Demo 1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //A specialised subclass of the {@link XYLineAndShapeRenderer} that requires
    // an {@link IntervalXYDataset} and represents the y-interval by shading an
    // area behind the y-values on the chart.
    DeviationRenderer renderer = new DeviationRenderer(true, false);
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1));
    renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1));
    renderer.setSeriesFillPaint(0, new Color(255, 200, 200));
    renderer.setSeriesFillPaint(1, new Color(200, 200, 255));
    plot.setRenderer(renderer);
    ////ww  w  . ja  v a2 s  . c  om
    NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:MonteCarloWindowLogic.java

static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull, ArrayList<Point2D> hits,
        ArrayList<Point2D> miss) {
    panelWhenInside.removeAll();/*w ww. j a  v  a2 s.  com*/
    panelWhenInside.setLayout(new java.awt.BorderLayout());

    XYSeries seriersHits = new XYSeries("Hits");
    convertArrayListToXYSeries(seriersHits, hits);

    XYSeries seriersMiss = new XYSeries("Miss");
    convertArrayListToXYSeries(seriersMiss, miss);
    //TODO refactor this, to handling hits, miss and than convex hull

    int pairsNumber = 0;
    if (convexHull != null)
        pairsNumber = convexHull.size() - 1;
    XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber];

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i);
    }

    if (convexHull != null) {
        divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull);
    }

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersHits);
    dataset.addSeries(seriersMiss);

    for (int i = 0; i < covnexHullDivideOnPiars.length; i++) {
        dataset.addSeries(covnexHullDivideOnPiars[i]);
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3));

    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShape(1, ShapeUtilities.createDiamond(3));

    for (int i = 2; i <= covnexHullDivideOnPiars.length + 1; i++) {
        renderer.setSeriesPaint(i, Color.black);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesStroke(i, new BasicStroke(1.0f));
    }

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();
}

From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java

/**
 * ?//from  w w w.ja v  a 2 s  . co  m
 * <P>
 * ?XYPlot? ???
 * <P>
 * ?:???TimeSeriesCollection?XYDataset?
 *
 * @param title 
 * @param titleFont 
 * @param timeAxisLabel 
 * @param valueAxisLabel 
 * @param data ??
 * @param legend 
 * @param tooltips ????
 * @param urls ??URL
 *
 * @return ?
 */
public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel,
        String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) {
    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02);

    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
        // new StandardXYToolTipGenerator(DateFormat.getDateInstance());
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

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

    return chart;

}

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

private static JFreeChart createTimeSeriesChart(XYDataset dataset) {
    //DomainAxis// w w w.  ja  va 2 s  . com
    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.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);
    //AbstractRenderer.dataBoundsIncludesVisibleSeriesOnly
    renderer.setDataBoundsIncludesVisibleSeriesOnly(false);
    renderer.setBaseSeriesVisibleInLegend(true);
    //Plot
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null) {
        private static final long serialVersionUID = 1L;

        //            public void rendererChanged(RendererChangeEvent event) {
        //                // if the event was caused by a change to series visibility, then
        //                // the axis ranges might need updating...
        //                if (event.getSeriesVisibilityChanged()) {
        ////                    configureDomainAxes();
        ////                    configureRangeAxes();
        //                }
        //                fireChangeEvent();
        //            }
    };
    plot.setRenderer(renderer);
    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:net.commerce.zocalo.freechart.ChartGenerator.java

public static JFreeChart createCustomXYStepAreaChart(TimePeriodValuesCollection top,
        TimePeriodValuesCollection bottom) {
    DateAxis xAxis = new DateAxis(null);
    NumberAxis yAxis = new NumberAxis("price");
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    yAxis.setUpperBound(100);/*from  www .  ja v a  2 s. co m*/
    yAxis.setLowerBound(0.0);

    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setDataset(0, top);
    plot.setDataset(1, bottom);
    XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    topRenderer.setRangeBase(1.0);
    topRenderer.setSeriesPaint(0, new Color(204, 255, 153));
    bottomRenderer.setSeriesPaint(0, new Color(51, 255, 204));
    plot.setRenderer(bottomRenderer);
    plot.setRenderer(1, topRenderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:com.tonbeller.jpivot.chart.ChartFactory.java

/**
 * Creates and returns a time series chart.
 * <P>//from w  ww  .j  a  v a  2  s. co m
 * A time series chart is an XYPlot with a date axis (horizontal) and a number axis (vertical),
 * and each data item is connected with a line.
 * <P>
 * Note that you can supply a TimeSeriesCollection to this method, as it implements the
 * XYDataset interface.
 *
 * @param title  the chart title.
 * @param timeAxisLabel  a label for the time axis.
 * @param valueAxisLabel  a label for the value axis.
 * @param data  the dataset for the chart.
 * @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 time series chart.
 */
public static JFreeChart createTimeSeriesChart(String title, java.awt.Font titleFont, String timeAxisLabel,
        String valueAxisLabel, XYDataset data, boolean legend, boolean tooltips, boolean urls) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins on the time axis
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    XYPlot plot = new XYPlot(data, timeAxis, valueAxis, null);

    XYToolTipGenerator tooltipGenerator = null;
    if (tooltips) {
        tooltipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
        //new StandardXYToolTipGenerator(DateFormat.getDateInstance());                                                
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES, tooltipGenerator, urlGenerator));

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

    return chart;

}

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

/**
 * DOC xqliu Comment method "createLineChart".
 * /*from w w w . j  a  v a2s. c o  m*/
 * @param title
 * @param dataset
 * @param showLegend
 * @return
 */
public static JFreeChart createLineChart(String title, XYDataset dataset, boolean showLegend) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    final JFreeChart chart = ChartFactory.createXYLineChart(null, title,
            Messages.getString("TopChartFactory.Percent"), dataset, PlotOrientation.VERTICAL, //$NON-NLS-1$
            showLegend, false, false);

    final XYPlot plot = chart.getXYPlot();

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

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

private static JFreeChart createXYAreaChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setOrientation(orientation);/*www .  j  ava 2s .  c o m*/
    plot.setForegroundAlpha(0.5f);

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

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    plot.setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA, tipGenerator, urlGenerator));
    JFreeChart chart = new JFreeChart("XYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    chart.setBackgroundPaint(Color.white);

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

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}