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:ws.moor.bt.gui.charts.BlockDownload.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Downloaded Blocks", "Time", "Blocks", dataset, true,
            false, false);//from   w  w w .j  a v  a 2 s. c  o m
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    return chart;
}

From source file:richclient.EvolutionChart.java

/**
 * Creates a chart.//from w  ww  .ja  v a  2 s . c  om
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
public JFreeChart createChart(XYDataset dataset) {

    // create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("Market evolution", // chart title
            "Time", // x axis label
            "Value", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java

/**
 * Creates a chart./*  w  ww.  j a  va 2  s  .  co  m*/
 *
 * @param dataset1  a dataset.
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset1, //power
        XYDataset dataset2, //costs
        XYDataset dataset3, long time) {

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

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();

    NumberAxis axis1 = new NumberAxis("power");
    NumberAxis axis2 = new NumberAxis("costs");
    axis1.setAutoRangeIncludesZero(true);
    axis1.setUpperBound(5000);
    axis1.setLowerBound(-5000);
    axis2.setAutoRangeIncludesZero(true);
    axis2.setUpperBound(50);
    axis2.setLowerBound(0);
    plot.setRangeAxis(0, axis1);
    plot.setRangeAxis(1, axis2);

    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 0);

    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);
    //TODO: SHADOWS OFF

    final StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    final StandardXYItemRenderer r2 = new StandardXYItemRenderer();
    final StandardXYItemRenderer r3 = new StandardXYItemRenderer();
    final StandardXYItemRenderer r4 = new StandardXYItemRenderer();
    plot.setRenderer(0, r1);
    plot.setRenderer(1, r2);
    plot.setRenderer(2, r3);
    plot.setRenderer(3, r4);

    int numberOfSeries = 0;
    numberOfSeries += dataset1.getSeriesCount();
    numberOfSeries += dataset2.getSeriesCount();
    numberOfSeries += dataset3.getSeriesCount();

    Color[] color = new Color[numberOfSeries];

    for (int i = 0; i < numberOfSeries / 2; i++) {
        color[i] = Color.getHSBColor(i * 1.0f / (numberOfSeries / 2), 1.0f, 1.0f);
    }

    int i = 0;

    for (int j = 0; j < dataset1.getSeriesCount() / 2; j++) {
        float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null);
        plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f));
        plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j + 1,
                Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f));
        i++;
    }
    for (int j = 0; j < dataset2.getSeriesCount() / 2; j++) {
        float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null);
        plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f));
        plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j + 1,
                Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f));
        i++;
    }
    for (int j = 0; j < dataset3.getSeriesCount() / 2; j++) {
        float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null);
        plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f));
        plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j + 1,
                Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f));
        i++;
    }

    // NOW line
    double upperBound = plot.getRangeAxis(1).getUpperBound();
    double lowerBound = plot.getRangeAxis(1).getLowerBound();

    XYSeries nowLine = new XYSeries("now");
    nowLine.add(time * 1000, lowerBound);
    nowLine.add(time * 1000, upperBound);
    XYSeriesCollection nowColl = new XYSeriesCollection(); //power axis
    nowColl.addSeries(nowLine);
    XYDataset nowSet = nowColl;

    plot.setDataset(3, nowSet);
    plot.mapDatasetToRangeAxis(3, 1);

    plot.getRendererForDataset(nowSet).setSeriesPaint(0, Color.DARK_GRAY);
    plot.getRendererForDataset(nowSet).setSeriesStroke(0, (Stroke) new BasicStroke(2.0f, BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f));

    plot.setDomainAxis(new DateAxis());
    plot.getDomainAxis().setAutoRange(false);

    long begin = (time / 86400) * 86400 * 1000; //beginning of day
    long end = begin + 86400 * 2 * 1000;

    plot.getDomainAxis().setRange(begin, end);

    return chart;

}

From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java

private JFreeChart createChart(String yLabel) {
    //Create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("Chart", "Time", yLabel, null);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);//  ww w. j  a v  a  2 s. com

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:be.ac.ua.comp.scarletnebula.gui.BareGraph.java

/**
 * @see Graph//ww  w . j a v a  2 s. co m
 */
@Override
public ChartPanel getChartPanel() {
    final XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    plot.setBackgroundPaint(Color.darkGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    final JFreeChart chart = new JFreeChart(null, new Font("SansSerif", Font.BOLD, 24), plot, true);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    return chartPanel;
}

From source file:edu.wustl.cab2b.client.ui.visualization.charts.LineChart.java

protected JFreeChart createChart(Dataset dataset) {
    XYDataset xyDataset = (XYDataset) dataset;
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Line Chart", "X", "Y", xyDataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    xyplot.setBackgroundPaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setShapesVisible(true);
    xylineandshaperenderer.setShapesFilled(true);

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return jfreechart;
}

From source file:net.relet.freimap.NodeInfo.java

private void sexupLayout(JFreeChart chart) {
    chart.setAntiAlias(true);//  w  ww  .  j av  a  2  s  .c  om
    chart.setBackgroundPaint(VisorFrame.bgcolor);
    chart.setBorderVisible(false);
    TextTitle title = chart.getTitle();
    title.setFont(VisorFrame.smallerfont);
    title.setPaint(VisorFrame.fgcolor);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(VisorFrame.bgcolor);
    plot.setDomainAxis(new DateAxis());
    sexupAxis(plot.getDomainAxis());
    sexupAxis(plot.getRangeAxis());
}

From source file:org.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java

/**
 * Creates a chart.//from w w  w .j  a  va  2s  . c  o  m
 * 
 * @param dataset
 *            a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset, XYPlot bpMeasureXYPlot) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Pressure Measure", // title
            "time(s)", // x-axis label
            "Pressure(mmHg)", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    bpMeasureXYPlot = (XYPlot) chart.getPlot();
    bpMeasureXYPlot.setBackgroundPaint(Color.lightGray);
    bpMeasureXYPlot.setDomainGridlinePaint(Color.white);
    bpMeasureXYPlot.setRangeGridlinePaint(Color.white);

    // bpMeasureXYPlot.setAxisOffset(new RectangleInsets(300, 0, 0,
    // BOUNDARY_NUMBER_OF_POINTS));
    // bpMeasureXYPlot.setDomainCrosshairVisible(true);
    // bpMeasureXYPlot.setRangeCrosshairVisible(true);

    XYItemRenderer r = bpMeasureXYPlot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    ValueAxis axis = bpMeasureXYPlot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    // axis.setRange(0, 1000);
    axis.setAutoRange(true);
    axis = bpMeasureXYPlot.getRangeAxis();
    axis.setRange(0, 300.0);

    // DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    // axis.setRange(0, 1000);

    return chart;

}

From source file:networkanalyzer.DynamicPing.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Ping Chart", //title
            "Time", //x-axis
            "Ping", //y-axis
            dataset, false, false, false);

    final XYPlot plot = result.getXYPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setAutoRange(true);//from ww w.j  a va 2s.  c o  m

    xaxis.setFixedAutoRange(60000.0);
    xaxis.setVerticalTickLabels(true);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setAutoRange(true);

    return result;

}

From source file:org.kurento.test.latency.ChartWriter.java

public void drawChart(String filename, int width, int height) throws IOException {
    // Create plot
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYSplineRenderer renderer = new XYSplineRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

    // Create chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    ChartUtilities.applyCurrentTheme(chart);
    ChartPanel chartPanel = new ChartPanel(chart, false);

    // Draw png//from   w  w  w.  j  a v a  2  s  .  c  om
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
    Graphics graphics = bi.getGraphics();
    chartPanel.setBounds(0, 0, width, height);
    chartPanel.paint(graphics);
    ImageIO.write(bi, "png", new File(filename));
}