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:ec.ui.view.StabilityView.java

@Override
protected void onColorSchemeChange() {
    pointsRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.BLUE));
    meanRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.RED));
    smoothRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.GREEN));

    XYPlot mainPlot = mainChart.getXYPlot();
    mainPlot.setBackgroundPaint(themeSupport.getPlotColor());
    mainPlot.setDomainGridlinePaint(themeSupport.getGridColor());
    mainPlot.setRangeGridlinePaint(themeSupport.getGridColor());
    mainChart.setBackgroundPaint(themeSupport.getBackColor());

    XYPlot detailPlot = detailChart.getXYPlot();
    detailPlot.setBackgroundPaint(themeSupport.getPlotColor());
    detailPlot.setDomainGridlinePaint(themeSupport.getGridColor());
    detailPlot.setRangeGridlinePaint(themeSupport.getGridColor());
    detailChart.setBackgroundPaint(themeSupport.getBackColor());

}

From source file:org.n52.server.io.render.DiagramRenderer.java

protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap,
        String[] observedProperties, ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            timeSeries.get(0), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );/*from ww w .j  a v a 2s.  c om*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // add additional datasets:
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setRange(begin.getTime(), end.getTime());
    axis.setDateFormatOverride(new SimpleDateFormat());
    axis.setTimeZone(end.getTimeZone());
    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = timeSeries.get(i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        // plot.getRangeAxis(i).setRange((Double)
        // overAllSeriesCollection.getMinimum(i),
        // (Double) overAllSeriesCollection.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
        // plot.getDataset().getXValue(i, i);
    }
    return chart;
}

From source file:me.childintime.childintime.ui.window.tool.BmiToolDialog.java

/**
 * Creates a chart.//from   www .  j a v a2 s.com
 *
 * @param dataset  the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    // Create the chart
    final JFreeChart chart = ChartFactory.createXYLineChart("BMI chart", "Age", "Value", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // Set the background color to the LAF's default
    chart.setBackgroundPaint(new JPanel().getBackground());

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < 3; i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesFillPaint(i, Color.RED);
    }
    plot.setRenderer(renderer);

    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // 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:com.rapidminer.gui.plotter.charts.HistogramChart.java

@Override
protected void updatePlotter() {
    prepareData();/*  ww  w. ja va  2 s. co m*/

    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Deviation plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.HistogramChart.parsing_property_error");
    }
    int categoryCount = this.histogramDataset.getSeriesCount();
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses && this.drawLegend;

    JFreeChart chart = ChartFactory.createHistogram(null, // title
            "Value", "Frequency", histogramDataset, PlotOrientation.VERTICAL, createLegend, true, // tooltips
            false); // urls

    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setForegroundAlpha(this.opaqueness);

    XYBarRenderer renderer = new XYBarRenderer();
    if (histogramDataset.getSeriesCount() == 1) {
        renderer.setSeriesPaint(0, ColorProvider.reduceColorBrightness(Color.RED));
        renderer.setSeriesFillPaint(0, ColorProvider.reduceColorBrightness(Color.RED));
    } else {
        for (int i = 0; i < histogramDataset.getSeriesCount(); i++) {
            Color color = getColorProvider(true)
                    .getPointColor((double) i / (double) (histogramDataset.getSeriesCount() - 1));
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesFillPaint(i, color);
        }
    }
    renderer.setBarPainter(new RapidXYBarPainter());
    // renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    plot.setRenderer(renderer);

    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);
    setRange(plot.getDomainAxis());

    // display correct x-Axis labels
    int count = histogramDataset.getSeriesCount();
    if (count > 0) {
        String key = histogramDataset.getSeriesKey(0).toString();
        int index = this.dataTable.getColumnIndex(key);
        if (index >= 0) {
            // Correctly displays nominal values on x-axis
            if (count == 1 && this.dataTable.isNominal(index)) {
                String[] values = new String[dataTable.getNumberOfValues(index)];
                for (int i = 0; i < values.length; i++) {
                    values[i] = dataTable.mapIndex(index, i);
                }
                plot.setDomainAxis(new SymbolAxis(key, values));
            }
            // Correctly displays dates on x-axis
            if (this.dataTable.isDateTime(index)) {
                boolean applyDateAxis = true;
                if (count > 1) {
                    for (int i = 1; i < count; i++) {
                        index = this.dataTable.getColumnIndex(histogramDataset.getSeriesKey(i).toString());
                        if (index < 0 || !this.dataTable.isDateTime(index)) {
                            applyDateAxis = false;
                            break;
                        }
                    }
                }
                if (applyDateAxis) {
                    DateAxis dateAxis = new DateAxis();
                    dateAxis.setDateFormatOverride(Tools.DATE_TIME_FORMAT.get());
                    plot.setDomainAxis(dateAxis);
                }
            }
        }

        // rotate labels
        if (isLabelRotating()) {
            plot.getDomainAxis().setTickLabelsVisible(true);
            plot.getDomainAxis().setVerticalTickLabels(true);
        }
    }

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // legend settings
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setPosition(RectangleEdge.TOP);
        legend.setFrame(BlockBorder.NONE);
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        legend.setItemFont(LABEL_FONT);
    }

    AbstractChartPanel panel = getPlotterPanel();
    if (panel == null) {
        panel = createPanel(chart);
    } else {
        panel.setChart(chart);
    }

    // Disable zooming for Histogram-Charts
    panel.setRangeZoomable(false);
    panel.setDomainZoomable(false);

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}

From source file:edu.ucla.stat.SOCR.chart.SuperXYChart.java

/**
 * Creates a chart./* w  w w.  j a v a 2s.c  om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

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

    return chart;

}

From source file:ec.ui.view.MarginView.java

@Override
protected void onColorSchemeChange() {
    XYPlot plot = chartPanel.getChart().getXYPlot();
    plot.setBackgroundPaint(themeSupport.getPlotColor());
    plot.setDomainGridlinePaint(themeSupport.getGridColor());
    plot.setRangeGridlinePaint(themeSupport.getGridColor());
    chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor());

    XYLineAndShapeRenderer main = (XYLineAndShapeRenderer) plot.getRenderer(MAIN_INDEX);
    main.setBasePaint(themeSupport.getLineColor(MAIN_COLOR));

    XYDifferenceRenderer difference = ((XYDifferenceRenderer) plot.getRenderer(DIFFERENCE_INDEX));
    Color diffArea = SwingColorSchemeSupport.withAlpha(themeSupport.getAreaColor(DIFFERENCE_COLOR), 150);
    difference.setPositivePaint(diffArea);
    difference.setNegativePaint(diffArea);
    difference.setBasePaint(themeSupport.getLineColor(DIFFERENCE_COLOR));

    Collection<Marker> markers = (Collection<Marker>) plot.getDomainMarkers(Layer.FOREGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(markers)) {
        Color markerColor = themeSupport.getLineColor(DATE_MARKER_COLOR);
        for (Marker o : markers) {
            o.setPaint(markerColor);/*from  w  w w  . j  a v a 2s.c o  m*/
        }
    }

    Collection<Marker> intervalMarkers = (Collection<Marker>) plot.getDomainMarkers(Layer.BACKGROUND);
    if (!Jdk6.Collections.isNullOrEmpty(intervalMarkers)) {
        Color markerColor = themeSupport.getLineColor(KnownColor.ORANGE);
        for (Marker o : intervalMarkers) {
            o.setPaint(markerColor);
        }
    }
}

From source file:MSUmpire.DIA.MixtureModelKDESemiParametric.java

public void GeneratePlot(String pngfile) throws IOException {
    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);

    double[] IDObs = new double[IDEmpiricalDist.getN()];
    double[] DecoyObs = new double[DecoyEmpiricalDist.getN()];

    for (int i = 0; i < IDEmpiricalDist.getN(); i++) {
        IDObs[i] = IDEmpiricalDist.getObs(i);
    }// ww  w  .  ja v a2s  .c o  m
    for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) {
        DecoyObs[i] = DecoyEmpiricalDist.getObs(i);
    }

    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    writer.write("UScore\tModel\tCorrect\tDecoy\n");
    for (int i = 0; i < NoBinPoints; i++) {
        model1.add(model_kde_x[i], decoy_kde_y[i]);
        model2.add(model_kde_x[i], correct_kde_y[i]);
        model3.add(model_kde_x[i], model_kde_y[i]);
        writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i]
                + "\n");
    }
    writer.close();

    MixtureModelProb = new float[NoBinPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoBinPoints + 1; i++) {
        double positiveNumber = correct_kde_y[NoBinPoints - i];
        double negativeNumber = decoy_kde_y[NoBinPoints - i];
        MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i];
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber));
        MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();

    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}

From source file:playground.dgrether.analysis.categoryhistogram.CategoryHistogramWriter.java

public JFreeChart getGraphic(final CategoryHistogram histo, final String modeName) {
    this.checkIndex(histo);
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries(this.departuresName, false, true);
    final XYSeries arrivalsSerie = new XYSeries(this.arrivalsName, false, true);
    final XYSeries onRouteSerie = new XYSeries(this.enRouteName, false, true);
    Integer enRoute = 0;//ww w .  j a v  a2s  .c  om
    for (int i = histo.getFirstIndex() - 2; i <= histo.getLastIndex() + 2; i++) {
        int departures = histo.getDepartures(modeName, i);
        int arrivals = histo.getArrivals(modeName, i);
        int stuck = histo.getAbort(modeName, i);
        enRoute = enRoute + departures - arrivals - stuck;
        double hour = i * histo.getBinSizeSeconds() / 60.0 / 60.0;
        departuresSerie.add(hour, departures);
        arrivalsSerie.add(hour, arrivals);
        onRouteSerie.add(hour, enRoute);
    }
    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            this.title + ", " + modeName + ", " + "it." + histo.getIteration(), "time [h]", yTitle, xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.DotChart.java

/**
 * Creates a chart./*from  w w  w  .j ava  2  s  . c  om*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart1(XYDataset dataset) {
    //System.out.println("createChart1 called");
    //   create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            "", // x axis label domain
            rangeLabel, // y axis label  range
            dataset, // data
            PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

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

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setBaseLinesVisible(false);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setUpperMargin(0.01);
    rangeAxis.setLowerMargin(0.01);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(true);
    domainAxis.setTickLabelsVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setUpperMargin(5);
    domainAxis.setLowerMargin(0.01);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    try {
        //   System.out.println("setting the common RangeAxis to null");
        common_rangeAxis = null;
        common_rangeAxis = (NumberAxis) rangeAxis.clone();
        //   System.out.println("creating the common RangeAxis");
    } catch (CloneNotSupportedException e) {
        System.out.println("CloneNotSupportedException!, exception caught");
    }

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, true, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, // !legendPanelOn,
            true, false);//w ww . j  av a 2 s  .com

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

    StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0"));
    renderer.setBaseToolTipGenerator(generator);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    axis.setLowerMargin(0.01);
    axis.setUpperMargin(0.01);
    //      setXSummary(dataset);  X  is time
    return chart;
}