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

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

Introduction

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

Prototype

public void setRangeGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the range axis 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 ww  w  . j a v  a 2  s .  c  om*/
    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:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java

/**
 * Creates a chart.//  w  w w . j  a v a2s  .  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);/*  www  .  ja v a 2 s  . c om*/

    // 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// w  ww .  j  ava  2 s  .c om
 */
@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:com.hello2morrow.sonargraph.jenkinsplugin.model.AbstractPlot.java

private void applyStandardPlotColors(XYPlot plot) {
    plot.setBackgroundPaint(BACK_GROUND_COLOR);
    plot.setRangeGridlinePaint(GRID_LINE_COLOR);
}

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//w  ww.ja  v a2  s .com
    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));
}

From source file:com.seniorproject.augmentedreality.chart.ChartCreator.java

private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart1 = ChartFactory.createXYLineChart(this.title[0], // chart title
            "Intensity", // x axis label
            "number of pixel", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from   w ww  .ja v  a  2s  . co  m

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

    //        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //        renderer.setSeriesLinesVisible(5, true);
    //        renderer.setSeriesShapesVisible(1, false);
    //        plot.setRenderer(renderer);
    //        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart1;
}

From source file:netplot.XYPlotPanel.java

private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xAxisName, yAxisName, dataset,
            PlotOrientation.VERTICAL, enableLegend, true, true);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    return chart;
}

From source file:netplot.TimeSeriesPlotPanel.java

private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(plotTitle, // title
            xAxisName, // x-axis label
            yAxisName, // y-axis label
            dataset, // data
            enableLegend, // create legend?
            true, // generate tooltips?
            true // generate URLs?
    );//  w ww .  j  a  va2s  .  co m

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    return chart;
}

From source file:bc.ui.swing.charts.LineChart.java

public void setModel(LineVisualModel line) {
    XYDataset dataset = createDataset(line);
    JFreeChart chart = ChartFactory.createXYLineChart(line.getTitle(), // chart title
            line.getDomainAxisLabel(), // x axis label
            line.getRangeAxisLabel(), // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from   ww w  .  j a  va2  s .  co  m

    chart.setBackgroundPaint(Color.white);

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

    renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

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

    renderer.setSeriesPaint(0, new Color(153, 215, 255));

    removeAll();
    chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}