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:org.hxzon.demo.jfreechart.XYDatasetDemo2.java

private static JFreeChart createXYLineChart(XYDataset dataset) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);/*ww w. ja  v  a 2 s  .  c o  m*/
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

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

    yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat());

    return chart;
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset,
        String outputdir, String type, String filename) throws IOException {
    JFreeChart jChart = null;//from   w  w w .  jav  a 2 s. c o m
    if ("line".equalsIgnoreCase(type)) {
        jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
    } else if ("bar".equalsIgnoreCase(type)) {
        System.out.println("Setting up jChart");
        jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
        System.out.println("Writing image....");
    } else if ("xyline".equalsIgnoreCase(type)) {
        jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset,
                PlotOrientation.VERTICAL, false, false, false);
    }

    if ("xyline".equalsIgnoreCase(type)) {

        XYPlot plot = (XYPlot) jChart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
        domain.setAutoRangeIncludesZero(false);

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount());
        //System.out.println("dataset.getRowCount(): " + dataset.getRowCount());

    } else {

        CategoryPlot plot = (CategoryPlot) jChart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setRangeZeroBaselineVisible(true);
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));

        CategoryAxis domain = (CategoryAxis) plot.getDomainAxis();
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount());
        //System.out.println("dataset.getRowCount(): " + dataset.getRowCount());

    }

    jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
    ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500);
}

From source file:Modelos.Grafica.java

private void configurarPlot(XYPlot plot) {
    plot.setDomainGridlinePaint(COLOR_RECUADROS_GRAFICA);
    plot.setRangeGridlinePaint(COLOR_RECUADROS_GRAFICA);
}

From source file:ch.unibe.iam.scg.archie.ui.charts.ConsultationNumberChart.java

/**
 * @see ch.unibe.iam.scg.archie.ui.charts.AbstractChartComposite#
 * initializeChart()/*from  w  w w  .  j a  v a  2 s  .  co  m*/
 */
@Override
protected JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(ConsultationNumberChart.CHART_TITLE, // title
            "", // x-axis label
            "Count", // y-axis label
            (XYDataset) this.creator.getDataset(), // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(new Color(this.parent.getBackground().getRed(),
            this.parent.getBackground().getGreen(), this.parent.getBackground().getBlue()));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

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

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;
}

From source file:loadmaprenderer.ChartTest.java

private JFreeChart makeChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("Cost/Year Chart", "Year", "Cost", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.BLUE);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);//from  w w w  .  j  a  va 2 s. c  o m
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRange(rootPaneCheckingEnabled);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(rootPaneCheckingEnabled);
    return chart;
}

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

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from   ww w .j  a v a 2  s . c om*/

    chart.setBackgroundPaint(Color.white);

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

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

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

    return chart;

}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the axis-related properties of a plot.
 * /* w  w w.  j  a va 2s. c  o  m*/
 * @param aPlot
 *            Plot to be updated.
 * @param aAxes
 *            Axis-related visual settings to be applied.
 * @param aGrid
 *            Grid-related visual settings to be applied.
 */
private static void updateAxes(XYPlot aPlot, AxesSettings aAxes, GridSettings aGrid, Range aDomainDataRange,
        Range aRangeDataRange) {

    aPlot.setDomainAxis(createAxis(aAxes, true, aDomainDataRange));
    aPlot.setRangeAxis(createAxis(aAxes, false, aRangeDataRange));

    aPlot.setDomainGridlinesVisible(aGrid.getVerticalGridLines()); // set gridlines for X axis
    aPlot.setDomainGridlinePaint(aGrid.getGridLinesColor()); // set color of domain gridline

    aPlot.setRangeGridlinesVisible(aGrid.getHorizontalGridLines()); // set gridlines for Y axis
    aPlot.setRangeGridlinePaint(aGrid.getGridLinesColor()); // set color of range gridline
}

From source file:Charts.LineChart.java

@Override
protected JFreeChart createChart(String title, String x, String y) {

    JFreeChart lineChart = this.makeJFreeChart(title, x, y);

    // Custom chart..
    lineChart.setBackgroundPaint(Color.white);

    final XYPlot plot = lineChart.getXYPlot();

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

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(0, false);
    plot.setRenderer(renderer);/*  w  w w. java 2  s  . c om*/

    return lineChart;
}

From source file:ch.unibe.iam.scg.archie.ui.charts.ConsultationMoneyChart.java

/**
 * @see ch.unibe.iam.scg.archie.ui.charts.AbstractChartComposite#
 * initializeChart()/*  w  ww.  j ava  2 s  .co  m*/
 */
@Override
protected JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(ConsultationMoneyChart.CHART_TITLE, // title
            "", // x-axis label
            "Amount", // y-axis label
            (XYDataset) this.creator.getDataset(), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    // Set chart background color to it's parents background
    chart.setBackgroundPaint(new Color(this.parent.getBackground().getRed(),
            this.parent.getBackground().getGreen(), this.parent.getBackground().getBlue()));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

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

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;
}

From source file:TradeMonitorGui.java

private XYPlot createChartFrame(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("Average Stock Price over 1 minute", "Time",
            "Price in USD", dataset, true, true, false);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(245, 245, 245));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);

    final JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setTitle("Trade Monitor");
    frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLayout(new BorderLayout());
    frame.add(new ChartPanel(chart));
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent windowEvent) {
            avgPrices.removeEntryListener(listenerId);
        }/*ww w . j av  a 2 s  . co  m*/
    });
    frame.setVisible(true);
    return plot;
}