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

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

Introduction

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

Prototype

public void setDomainGridlinesVisible(boolean visible) 

Source Link

Document

Sets the flag that controls whether or not the domain grid-lines are visible.

Usage

From source file:jamel.gui.charts.TimeChart.java

/**
 * Returns a new time plot.//w  ww .j a v a 2s .co  m
 * @param timeSeries  the time series.
 * @param valueAxisLabel the value axis label.
 * @return a new time plot.
 */
private static Plot newTimePlot(TimeSeries[] timeSeries, String valueAxisLabel) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.setXPosition(TimePeriodAnchor.MIDDLE);
    for (int i = 0; i < timeSeries.length; i++) {
        TimeSeries series = timeSeries[i];
        if (series == null)
            throw new RuntimeException();
        dataset.addSeries(series);
    }
    final XYPlot plot = new XYPlot(dataset, new DateAxis(), new NumberAxis(valueAxisLabel),
            new XYLineAndShapeRenderer(true, false));
    ((DateAxis) plot.getDomainAxis()).setAutoRange(false);
    ((DateAxis) plot.getDomainAxis()).setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    plot.setDomainGridlinesVisible(false);
    return plot;
}

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

private static JFreeChart createChart(BoxAndWhiskerXYDataset boxandwhiskerxydataset) {
    DateAxis dateaxis = new DateAxis("Day");
    NumberAxis numberaxis = new NumberAxis("Value");
    XYBoxAndWhiskerRenderer xyboxandwhiskerrenderer = new XYBoxAndWhiskerRenderer();
    XYPlot xyplot = new XYPlot(boxandwhiskerxydataset, dateaxis, numberaxis, xyboxandwhiskerrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart jfreechart = new JFreeChart("Box-and-Whisker Chart Demo 2", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java

private static JFreeChart chartProfile(int length, TimeSeriesCollection dataset, String descriptor,
        String yax) {//from  ww  w  .j a  v  a2 s.  c  o  m
    JFreeChart chart = ChartFactory.createTimeSeriesChart(descriptor, "Time", yax, dataset);

    // ChartFactory.createXYLineChart("TimeProfile", "Time", "Wait Time
    // [s]", dataset,
    // PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setBackgroundPaint(Color.white);

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRange(true);

    XYItemRenderer renderer = plot.getRenderer();
    for (int s = 0; s < length; s++) {
        renderer.setSeriesStroke(s, new BasicStroke(2));
    }

    return chart;
}

From source file:org.gumtree.vis.awt.PlotFactory.java

public static JFreeChart createXYBlockChart(IXYZDataset dataset) {
    NumberAxis xAxis = createXAxis(dataset);
    NumberAxis yAxis = createYAxis(dataset);
    NumberAxis scaleAxis = createScaleAxis(dataset);

    float min = (float) dataset.getZMin();
    float max = (float) dataset.getZMax();
    PaintScale scale = generateRainbowScale(min, max, StaticValues.DEFAULT_COLOR_SCALE);
    XYBlockRenderer renderer = createRender(dataset, scale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainPannable(true);//from   www  .j  a  va2s.  c  o  m
    plot.setRangePannable(true);

    JFreeChart chart = new JFreeChart(dataset.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    //      chart = new JFreeChart(dataset.getTitle(), plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    PaintScale scaleBar = generateRainbowScale(min, max, StaticValues.DEFAULT_COLOR_SCALE);
    PaintScaleLegend legend = createScaleLegend(scale, scaleAxis);
    legend.setSubdivisionCount(ColorScale.DIVISION_COUNT);
    //      legend.setStripOutlineVisible(true);
    chart.addSubtitle(legend);
    chart.setBorderVisible(true);
    //      ChartUtilities.applyCurrentTheme(chart);
    chartTheme.apply(chart);
    chart.fireChartChanged();
    return chart;
}

From source file:com.alibaba.dubbo.monitor.simple.SimpleMonitorService.java

private static void createChart(String key, String service, String method, String date, String[] types,
        Map<String, long[]> data, double[] summary, String path) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
    DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
    TimeSeriesCollection xydataset = new TimeSeriesCollection();
    for (int i = 0; i < types.length; i++) {
        String type = types[i];/*from  w  ww.  j  a  va2  s  . com*/
        TimeSeries timeseries = new TimeSeries(type);
        for (Map.Entry<String, long[]> entry : data.entrySet()) {
            try {
                timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            }
        }
        xydataset.addSeries(timeseries);
    }
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
            "max: " + numberFormat.format(summary[0])
                    + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "") + " avg: "
                    + numberFormat.format(summary[2])
                    + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""),
            toDisplayService(service) + "  " + method + "  " + toDisplayDate(date), key, xydataset, true, true,
            false);
    jfreechart.setBackgroundPaint(Color.WHITE);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setRangeGridlinePaint(Color.GRAY);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    BufferedImage image = jfreechart.createBufferedImage(600, 300);
    try {
        if (logger.isInfoEnabled()) {
            logger.info("write chart: " + path);
        }
        File methodChartFile = new File(path);
        File methodChartDir = methodChartFile.getParentFile();
        if (methodChartDir != null && !methodChartDir.exists()) {
            methodChartDir.mkdirs();
        }
        FileOutputStream output = new FileOutputStream(methodChartFile);
        try {
            ImageIO.write(image, "png", output);
            output.flush();
        } finally {
            output.close();
        }
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
    }
}

From source file:ec.util.chart.swing.Charts.java

/**
 * A sparkline is a type of information graphic characterized by its small
 * size and high data density. Sparklines present trends and variations
 * associated with some measurement, such as average temperature or stock
 * market activity, in a simple and condensed way. Several sparklines are
 * often used together as elements of a small multiple.<br>
 *
 * {@link http://en.wikipedia.org/wiki/Sparkline}
 *
 * @param dataset// w  w w . ja  va 2 s . co m
 * @return
 * @author Philippe Charles
 */
@Nonnull
public static JFreeChart createSparkLineChart(@Nonnull XYDataset dataset) {
    JFreeChart result = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    result.setBorderVisible(false);
    result.setBackgroundPaint(null);
    result.setAntiAlias(true);
    XYPlot plot = result.getXYPlot();
    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setOutlineVisible(false);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    plot.setBackgroundPaint(null);
    ((XYLineAndShapeRenderer) plot.getRenderer()).setAutoPopulateSeriesPaint(false);
    return result;
}

From source file:classpackage.ChartGalaxy.java

private static JFreeChart createChart(final XYDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("MDS Galaxy", "X", "Y", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setBaseItemLabelGenerator(new LabelGenerator());
    renderer.setBaseItemLabelPaint(Color.WHITE);//label
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(15f));
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    //set false para linhas no grafico
    xyPlot.setDomainGridlinesVisible(false);
    xyPlot.setRangeGridlinesVisible(false);
    xyPlot.setRangeMinorGridlinesVisible(false);
    xyPlot.setRangeCrosshairVisible(false);
    xyPlot.setRangeCrosshairLockedOnData(false);
    xyPlot.setRangeZeroBaselineVisible(false);
    xyPlot.setBackgroundPaint(Color.BLACK);
    double size = 40.0;
    double delta = size / 2.0;
    Shape shape = new Rectangle2D.Double(-delta, -delta, size, size);

    renderer.setSeriesShape(0, shape);/*from   w  ww . j  a  v  a 2  s .c o m*/
    renderer.setSeriesPaint(0, transparent);

    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setRange(-0.1, 0.1);
    domain.setTickUnit(new NumberTickUnit(0.1));
    domain.setVerticalTickLabels(true);
    NumberAxis range = (NumberAxis) xyPlot.getRangeAxis();
    range.setRange(-0.1, 0.1);
    range.setTickUnit(new NumberTickUnit(0.1));

    return jfreechart;
}

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

/**
 * Updates the axis-related properties of a plot.
 * /*from w  w  w  . j  a v  a 2  s  .  c om*/
 * @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:org.ala.spatial.web.services.GDMWSController.java

public static void generateChart5(String outputdir, String plotName, String plotData) {
    try {//from  w  ww . j  av a 2  s .c  o m

        CSVReader csv = new CSVReader(new FileReader(plotData));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht = new double[2][rawdata.size() - 1];
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            dataCht[0][i - 1] = Double.parseDouble(row[0]);
            dataCht[1][i - 1] = Double.parseDouble(row[1]);
        }

        DefaultXYDataset dataset = new DefaultXYDataset();
        dataset.addSeries("", dataCht);

        System.out.println("Setting up jChart for " + plotName);
        //generateChartByType(plotName, plotName, "f("+plotName+")", null, outputdir, "xyline", plotName);
        JFreeChart jChart = ChartFactory.createXYLineChart(plotName, plotName, "f(" + plotName + ")", dataset,
                PlotOrientation.VERTICAL, false, false, false);

        jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

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

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        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("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + ".png"), jChart, 500, 500);
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + "_thumb.png"), jChart, 210,
                140);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeXYPlot(XYPlot plot, ChartParams params) {
    customizePlot(plot, params);//from  www  .  ja v a  2  s.  c o m

    if (params.get(ChartParams.XYPLOT_ORIENTATION) != null) {
        plot.setOrientation(params.getPlotOrientation(ChartParams.XYPLOT_ORIENTATION));
    }

    if (params.get(ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX) != null) {
        if (params.getBoolean(ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX)
                .booleanValue()) {
            plot.setDomainGridlinesVisible(true);
            if (params.get(
                    ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX) != null) {
                plot.setDomainGridlinePaint(params.getColor(
                        ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX));
            }

            if (params.get(
                    ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX) != null) {
                plot.setDomainGridlineStroke(params.getStroke(
                        ChartParams.AXIS_DOMAIN_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX));
            }
        } else {
            plot.setDomainGridlinesVisible(false);
        }
    }

    if (params.get(ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX) != null) {
        if (params.getBoolean(ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX)
                .booleanValue()) {
            plot.setRangeGridlinesVisible(true);
            if (params.get(
                    ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX) != null) {
                plot.setRangeGridlinePaint(params.getColor(
                        ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX));
            }

            if (params.get(
                    ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX) != null) {
                plot.setRangeGridlineStroke(params.getStroke(
                        ChartParams.AXIS_RANGE_PREFIX + ChartParams.PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX));
            }
        } else {
            plot.setRangeGridlinesVisible(false);
        }
    }

    if (params.get(ChartParams.XYPLOT_QUADRANT_ORIGIN) != null) {
        plot.setQuadrantOrigin(params.getPoint2D(ChartParams.XYPLOT_QUADRANT_ORIGIN));
    }

    if (params.get(ChartParams.XYPLOT_QUADRANT_COLORS) != null) {
        List colors = params.getList(ChartParams.XYPLOT_QUADRANT_COLORS);
        for (int i = 0; i < 4 && i < colors.size(); i++) {
            if (colors.get(i) != null) {
                plot.setQuadrantPaint(i, (Color) colors.get(i));
            }
        }
    }
}