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

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

Introduction

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

Prototype

public void setDomainGridlinePaint(Paint paint) 

Source Link

Document

Sets the paint for the grid lines plotted against the domain axis, and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:finalproject.GraphData.java

/**
 * Creates a chart with the data that is graphed vs time
 * @param data//from  www.j a  v  a2  s.c  om
 * @param names
 * @return 
 */
public JFreeChart graphVsTime(String[][] data, String[] names) {
    TimeSeries mySeries = new TimeSeries("Data");

    for (int i = 0; i < data.length; i++) {
        if (data[i][0] != null && data[i][1] != null)
            mySeries.add(new Hour(convertTime(data[i][0]), day), Integer.parseInt(data[i][1]));
    }

    TimeSeriesCollection collection = new TimeSeriesCollection(mySeries);

    XYDataset dataset = collection;

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Glucose vs Time", names[0], names[1], dataset,
            true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);

    return chart;
}

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

/**
 * @see Graph//from   w ww.j a  va  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);

    if (stream.getMax() != null) {
        log.info("Getting chart panel for stream with maximum.");
        range.setAutoRange(false);

        range.setTickUnit(new NumberTickUnit(stream.getMax() / 10, new DecimalFormat(), 1));
        range.setRange(0, stream.getMax());
    } else if (stream.getType() == Type.RELATIVE) {
        range.setAutoRange(false);

        range.setTickUnit(new NumberTickUnit(0.1, new DecimalFormat(), 1));
        range.setRange(0, 1);
    } else {
        double sum = 0;
        final List<TimedDatapoint> datapoints = stream.getRecentlyProcessedDatapoints();

        range.setTickUnit(
                new NumberTickUnit((int) (Utils.max(datapoints).getValue() / 5) + 1, new DecimalFormat(), 1));
    }

    final JFreeChart chart = new JFreeChart(stream.getStreamname(), new Font("SansSerif", Font.PLAIN, 20), 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:gui.Plotter1D.java

private ChartPanel createChartPanel1(String grapheName) {

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    ValueAxis valueAxis = new NumberAxis("X");
    valueAxis.setRange(0.0, 1.0);/*from  w  w w.  ja  va2  s.  com*/
    ValueAxis valueAxisy = new NumberAxis("Y");
    valueAxis.setRange(0.0, 1.0);
    XYPlot xyplot;
    xyplot = new XYPlot(xyseriescollection, valueAxis, valueAxisy, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart(grapheName, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, false);
    return chartpanel;
}

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

/**
 * Creates a chart./*from  ww  w  . j  a v a 2  s.  c  o  m*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Weekly Data", "Date", "Value", dataset, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //      sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 1, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM ''yy")));
    axis.setStandardTickUnits(standardUnits);

    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 w w  w . jav  a  2  s .  c  o m*/

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

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

    return result;

}

From source file:gui.DendrogramChart.java

ChartPanel getChartPanel(Dendrogram d, boolean log) {
    JFreeChart chart = ChartFactory.createXYLineChart(null, "Similarity", "No. of Groups", null,
            PlotOrientation.VERTICAL, true, true, false);

    setChartData(chart, log);/*from   w ww .  j a  va  2  s.c  o m*/

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    chart.setRenderingHints(rh);
    chart.removeLegend();

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(255, 255, 220));
    plot.setDomainGridlinePaint(new Color(128, 128, 128));
    plot.setRangeGridlinePaint(new Color(128, 128, 128));
    if (log == false) {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setLowerBound(0);
        rangeAxis.setNumberFormatOverride(new DecimalFormat("0"));
        rangeAxis.setLabelFont(Prefs.labelFont);
    } else {
        // LogarithmicAxis logXAxis = new LogarithmicAxis("Similarity");
        // logXAxis.setAllowNegativesFlag(true);
        LogarithmicAxis logYAxis = new LogarithmicAxis("No. Of Groups");
        logYAxis.setAllowNegativesFlag(false);

        // plot.setDomainAxis(logXAxis);
        plot.setRangeAxis(logYAxis);
    }

    ChartPanel chartPanel = new ChartPanel(chart);
    // chartPanel.setPopupMenu(null);
    return chartPanel;
}

From source file:net.sf.profiler4j.console.AllocDiffPanel.java

public AllocDiffPanel(int maxAgeMillis) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Allocs/Sec", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAgeMillis);

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);

    NumberAxis numberAxis = new NumberAxis("Allocs/Sec");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);//w  w w .j  a v a2 s  .  c o m
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart("Object Allocactions in Remote JVM",
            new Font("SansSerif", Font.PLAIN, 18), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}

From source file:sanger.team16.gui.genevar.eqtl.gene.RegionalPlot.java

private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold,
        XYDataset dataset) {//from  w  w  w .  jav  a 2s. c  o m
    JFreeChart chart = ChartFactory.createScatterPlot(null,
            "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.lightGray);
    //plot.setRangeCrosshairVisible(true);

    //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setRange(geneStart - distance, geneStart + distance);       
    //domainAxis.setUpperMargin(1000);
    //domainAxis.setLowerMargin(1000);

    //ValueAxis rangeAxis = plot.getRangeAxis();
    //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5);
    //rangeAxis.setLowerBound(0);

    XYItemRenderer renderer = plot.getRenderer();
    int size = dataset.getSeriesCount();
    for (int i = 0; i < size; i++) {
        //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4);
        //renderer.setSeriesPaint(i, new Color(255, scale, scale));

        renderer.setSeriesPaint(i, new Color(255, 0, 0));
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3));
        renderer.setBaseSeriesVisibleInLegend(false);
    }

    ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold));
    upperMarker.setPaint(Color.gray);
    //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);        
    //upperMarker.setLabel("-log10(10E-4)");
    //upperMarker.setLabelPaint(Color.red);
    //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    float[] f = { 4, 3, 4, 3 };
    upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f));
    plot.addRangeMarker(upperMarker);

    ValueMarker marker = new ValueMarker(0.0);
    marker.setPaint(Color.lightGray);
    plot.addRangeMarker(marker);

    XYSeries series = new XYSeries("Range");
    series.add(geneStart - distanceToTSS, -0.05);
    series.add(geneStart + distanceToTSS, -0.05);
    ((XYSeriesCollection) dataset).addSeries(series);
    renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false);

    return chart;
}

From source file:sanger.team16.gui.genevar.mqtl.gene.RegionalPlot.java

private JFreeChart createChart(String geneChromosome, int geneStart, int distanceToTSS, double threshold,
        XYDataset dataset) {//w w w  .j a  v a2 s.co m
    JFreeChart chart = ChartFactory.createScatterPlot(null,
            "Position on chromosome " + geneChromosome + " (bp)", "-log10(P)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    //plot.setRangeGridlinePaint(Color.lightGray);
    //plot.setRangeCrosshairVisible(true);

    //NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setRange(geneStart - distance, geneStart + distance);       
    //domainAxis.setUpperMargin(1000);
    //domainAxis.setLowerMargin(1000);

    //ValueAxis rangeAxis = plot.getRangeAxis();
    //rangeAxis.setUpperMargin(dataset.getYValue(0, 0)/5);
    //rangeAxis.setLowerBound(0);

    XYItemRenderer renderer = plot.getRenderer();
    int size = dataset.getSeriesCount();
    for (int i = 0; i < size; i++) {
        //int scale = (int) Math.round((255 - (255 * dataset.getYValue(i, 0)) / top) / 1.4);
        //renderer.setSeriesPaint(i, new Color(255, scale, scale));

        renderer.setSeriesPaint(i, new Color(50, 205, 50));
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond((float) 3));
        renderer.setBaseSeriesVisibleInLegend(false);
    }

    ValueMarker upperMarker = new ValueMarker(-Math.log10(threshold));
    upperMarker.setPaint(Color.gray);
    //upperMarker.setLabelOffsetType(LengthAdjustmentType.EXPAND);        
    //upperMarker.setLabel("-log10(10E-4)");
    //upperMarker.setLabelPaint(Color.red);
    //upperMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    //upperMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    float[] f = { 4, 3, 4, 3 };
    upperMarker.setStroke(new BasicStroke(1.0f, 1, 1, 0, f, 1.0f));
    plot.addRangeMarker(upperMarker);

    ValueMarker marker = new ValueMarker(0.0);
    marker.setPaint(Color.lightGray);
    plot.addRangeMarker(marker);

    XYSeries series = new XYSeries("Range");
    series.add(geneStart - distanceToTSS, -0.05);
    series.add(geneStart + distanceToTSS, -0.05);
    ((XYSeriesCollection) dataset).addSeries(series);
    renderer.setSeriesVisible(dataset.getSeriesCount() - 1, false, false);

    return chart;
}

From source file:net.sf.profiler4j.console.MemoryPlotPanel.java

public MemoryPlotPanel(int maxAge, String title) {
    super(new BorderLayout());

    totalSeries = new TimeSeries("Committed Memory", Millisecond.class);
    totalSeries.setMaximumItemAge(maxAge);
    usedSeries = new TimeSeries("Used Memory", Millisecond.class);
    usedSeries.setMaximumItemAge(maxAge);
    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    seriesCollection.addSeries(totalSeries);
    seriesCollection.addSeries(usedSeries);

    NumberAxis numberAxis = new NumberAxis("Memory (KB)");
    numberAxis.setLabelFont(new Font("SansSerif", 0, 14));
    numberAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    DateAxis dateAxis = new DateAxis("Time");
    dateAxis.setTickLabelFont(new Font("SansSerif", 0, 12));
    dateAxis.setLabelFont(new Font("SansSerif", 0, 14));
    dateAxis.setAutoRange(true);/*from w w w  .j av  a2s . c om*/
    dateAxis.setLowerMargin(0);
    dateAxis.setUpperMargin(0);
    dateAxis.setTickLabelsVisible(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesPaint(1, Color.GREEN.darker());
    lineRenderer.setStroke(new BasicStroke(2F, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    XYPlot xyplot = new XYPlot(seriesCollection, dateAxis, numberAxis, lineRenderer);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

    JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.PLAIN, 14), xyplot, true);
    chart.setBackgroundPaint(Color.white);

    ChartPanel panel = new ChartPanel(chart);
    panel.setBorder(createCompoundBorder(createEmptyBorder(8, 8, 8, 8), createLineBorder(Color.LIGHT_GRAY)));
    add(panel);
    setBorder(createEmptyBorder(8, 8, 8, 8));
}