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

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

Introduction

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

Prototype

public void setBackgroundPaint(Paint paint) 

Source Link

Document

Sets the background color of the plot area and sends a PlotChangeEvent to all registered listeners.

Usage

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

private static JFreeChart createHighLowChart(OHLCDataset dataset) {
    ValueAxis timeAxis = new DateAxis(xAxisLabel);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart("HighLow 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);

    return chart;
}

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

private static void formatColorTheme(JFreeChart chart, ColorTheme theme) {
    Plot rawPlot = chart.getPlot();//from   w ww. j  ava  2 s  .c  om

    Paint background = Color.BLACK;
    Paint foregroung = Color.WHITE;
    if (theme == ColorTheme.LIGHT) {
        background = Color.WHITE;
        foregroung = Color.BLACK;
    }

    chart.setBackgroundPaint(background);
    chart.getLegend().setBackgroundPaint(background);
    chart.getLegend().setItemPaint(foregroung);

    if (rawPlot instanceof XYPlot) {
        XYPlot plot = (XYPlot) rawPlot;
        plot.getDomainAxis().setLabelPaint(foregroung);
        plot.getRangeAxis().setLabelPaint(foregroung);
        plot.getDomainAxis().setTickLabelPaint(foregroung);
        plot.getDomainAxis().setTickMarkPaint(foregroung);
        plot.getRangeAxis().setTickLabelPaint(foregroung);
        plot.getRangeAxis().setTickMarkPaint(foregroung);
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(foregroung);
        plot.setRangeGridlinePaint(foregroung);
    }
    if (rawPlot instanceof CategoryPlot) {
        CategoryPlot plot = (CategoryPlot) rawPlot;
        plot.getDomainAxis().setLabelPaint(foregroung);
        plot.getRangeAxis().setLabelPaint(foregroung);
        plot.getDomainAxis().setTickLabelPaint(foregroung);
        plot.getDomainAxis().setTickMarkPaint(foregroung);
        plot.getRangeAxis().setTickLabelPaint(foregroung);
        plot.getRangeAxis().setTickMarkPaint(foregroung);
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(foregroung);
        plot.setRangeGridlinePaint(foregroung);
    }
}

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

private static JFreeChart createBoxAndWhiskerChart(BoxAndWhiskerXYDataset dataset) {
    ValueAxis timeAxis = new DateAxis(xAxisLabel);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart("BoxAndWhiskerXY Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot,
            legend);//from  www .j av a2 s  .  co m
    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);

    return chart;
}

From source file:org.xapagy.ui.tempdyn.GraphEvolution.java

/**
 * Creates a chart the style we like./*from   ww w.  ja v a  2  s.  com*/
 * 
 * @param chart
 */
public static void setChartProperties(JFreeChart chart, List<SimpleEntry<Color, Stroke>> lineStyles) {
    // set the background and title font
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14));
    // set the background and the grid all white
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setBackgroundPaint(Color.white);
    // now
    plot.setOutlineStroke(null);

    XYItemRenderer rend = plot.getRenderer();
    Stroke stroke = new BasicStroke(2.0f);
    rend.setBaseStroke(stroke);
    // rend.setDrawSeriesLineAsPath(true);

    // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
    // BasicStroke.JOIN_ROUND, 10, new float[] {10, 10}, 0);
    // strokes.add(stroke);
    // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
    // BasicStroke.JOIN_ROUND, 10, new float[] {2, 4}, 0);
    // strokes.add(stroke);
    int seriesCount = plot.getSeriesCount();
    for (int i = 0; i != seriesCount; i++) {
        SimpleEntry<Color, Stroke> lineStyle = lineStyles.get(i % lineStyles.size());
        rend.setSeriesStroke(i, lineStyle.getValue());
        rend.setSeriesPaint(i, lineStyle.getKey());
    }
}

From source file:y.graphs.ChartHelperELF.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleMagGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleMagGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );//from  w  w w  . ja v a2s.  c o m

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundELF());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthELF());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //            renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //        rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

From source file:y.graphs.ChartHelperSRB.java

private static JFreeChart createChart(final TimeSeriesCollection dataset, Date from, Date to, Config config,
        ArrayList<ConfigSerie> series) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(Config.getResource("MsgTitleSrbGraph"),
            Config.getResource("TitleDate"), Config.getResource("MsgTitleSrbGraphYAxis"), dataset, true, // include legend
            true, // tooltips
            false // urls
    );/*from   w  w  w.  j  ava  2 s  .c o m*/

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 12));
    lt.setBackgroundPaint(Color.white);
    lt.setFrame(new BlockBorder(Color.white));
    lt.setVerticalAlignment(VerticalAlignment.CENTER);
    XYTitleAnnotation ta = new XYTitleAnnotation(config.getLegendX(), config.getLegendY(), lt,
            RectangleAnchor.TOP_RIGHT);
    ta.setMaxWidth(config.getLegendSize());
    plot.addAnnotation(ta);
    chart.removeLegend();

    plot.setBackgroundPaint(config.getColorBackgroundSRB());
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    final Stroke lineStroke = new BasicStroke((float) config.getLineWidthSRB());

    for (int si = 0; si < series.size(); si++) {
        final ConfigSerie cs = series.get(si);
        renderer.setSeriesLinesVisible(si, cs.isDrawLine());

        final float size = cs.getShapeSize();
        renderer.setSeriesShapesVisible(si, size > 0);
        if (size > 0)
            renderer.setSeriesShape(si, ShapeUtilities.createRegularCross(size, size));

        renderer.setSeriesStroke(si, lineStroke);
        //          renderer.setSeriesOutlineStroke(si, lineStroke);
        renderer.setSeriesPaint(si, cs.getColor());
    }
    plot.setRenderer(renderer);

    // x axis
    final DateAxis rangeAxis = (DateAxis) plot.getDomainAxis();
    //      rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); // Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to
    rangeAxis.setAutoRange(true);
    //        rangeAxis.setRange(from, to);
    rangeAxis.setLowerMargin(0.01);
    rangeAxis.setUpperMargin(0.01);

    {
        final Font axisFont = config.getAxisFont();
        if (axisFont != null) {
            rangeAxis.setLabelFont(axisFont);
            plot.getRangeAxis().setLabelFont(axisFont);
        }
    }

    final String xaxisFmt = config.getAxisFormat();

    if (xaxisFmt == null || xaxisFmt.isEmpty()) {
        double diffInDays = (to.getTime() - from.getTime()) / (1000.0 * 60.0 * 60.0 * 24.0);
        if (diffInDays < 2)
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_TIMEFMT, DateFormatSymbols.getInstance()));
        else
            rangeAxis.setDateFormatOverride(
                    new SimpleDateFormat(Config.DEFAULT_SHORTTIMEFMT, DateFormatSymbols.getInstance()));
    } else
        rangeAxis.setDateFormatOverride(new SimpleDateFormat(xaxisFmt, DateFormatSymbols.getInstance()));

    final ValueAxis domain = plot.getRangeAxis();
    if (config.getForceYmin() != 0 || config.getForceYmax() != 0)
        domain.setRange(ElfValue.valueIntToDouble(config.getForceYmin()),
                ElfValue.valueIntToDouble(config.getForceYmax()));

    // title
    final Font titleFont = config.getTitleFont();
    if (titleFont != null)
        chart.getTitle().setFont(titleFont);

    return chart;
}

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

private static JFreeChart createCandlestickChart(OHLCDataset dataset) {
    ValueAxis timeAxis = new DateAxis(xAxisLabel);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart("Candlestick 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);

    return chart;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

public static JFreeChart createHistogram(XYSeries series, double barwidth, String yAxisLabel) {
    XYSeriesCollection xydata = new XYSeriesCollection(series);
    XYBarDataset dataset = new XYBarDataset(xydata, barwidth);
    JFreeChart chart = ChartFactory.createXYBarChart("", yAxisLabel, false, "n", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot xyplot = chart.getXYPlot();
    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    xyplot.setForegroundAlpha(0.7F);/*  w ww . ja  v  a2s  . c  o m*/
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    xybarrenderer.setDrawBarOutline(false);
    return chart;
}

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

private static JFreeChart createXYBarChart(XYDataset dataset) {
    boolean dateAxis = true;
    ValueAxis domainAxis = null;/* ww w  .j  ava 2 s.  c  o m*/
    if (dateAxis) {
        domainAxis = new DateAxis(xAxisLabel);
    } else {
        NumberAxis axis = new NumberAxis(xAxisLabel);
        axis.setAutoRangeIncludesZero(false);
        domainAxis = axis;
    }
    ValueAxis valueAxis = new NumberAxis(yAxisLabel);

    XYBarRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        XYToolTipGenerator tt;
        if (dateAxis) {
            tt = StandardXYToolTipGenerator.getTimeSeriesInstance();
        } else {
            tt = new StandardXYToolTipGenerator();
        }
        renderer.setBaseToolTipGenerator(tt);
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart("XYBar 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);

    return chart;
}

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

private static JFreeChart createStackedXYAreaChart(TableXYDataset dataset) {
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);//from w w  w .j a v  a 2  s  .  com
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator);
    renderer.setOutline(true);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);

    plot.setRangeAxis(yAxis); // forces recalculation of the axis range

    JFreeChart chart = new JFreeChart("StackedXYArea 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);

    return chart;
}