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

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

Introduction

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

Prototype

public void setRangeGridlinesVisible(boolean visible) 

Source Link

Document

Sets the flag that controls whether or not the range axis grid lines are visible.

Usage

From source file:pisco.batch.visu.BatchingChartFactory.java

public static XYPlot createLatenessPlot(Batch[] batches) {
    final Paint[] palette = makePalette(batches.length);
    XYBarRenderer renderer = new XYBarRendererPaletteBySeries(palette);
    renderer.setUseYInterval(true);/* ww  w .j a  v a 2  s. co  m*/
    renderer.setDrawBarOutline(true);
    final LatenessLabelToolTipGenerator bpg = new LatenessLabelToolTipGenerator(batches);
    renderer.setBaseItemLabelGenerator(bpg);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseToolTipGenerator(bpg);
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    XYPlot plot = new XYPlot(createLatenessDataset(batches), null, createIntegerAxis("Batches"), renderer);
    plot.setRangeGridlinesVisible(false);
    makeDueDateMarkers(plot, batches, palette);
    return plot;
}

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

private static JFreeChart chartProfile(int length, TimeSeriesCollection dataset, String descriptor,
        String yax) {//from www  .  j  a v  a  2 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: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  va 2  s.  co  m
        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/*from   w w  w .  j a v  a 2s . 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);//ww w.  jav a2 s . c om
    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:org.talend.dataprofiler.chart.util.TopChartFactory.java

public static JFreeChart createBlockingBarChart(String title, HistogramDataset dataset) {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart chart = ChartFactory.createHistogram(null, title, "Key frequency", dataset, //$NON-NLS-1$
            PlotOrientation.VERTICAL, false, true, false);

    XYPlot plot = chart.getXYPlot();
    plot.getRangeAxis().setUpperMargin(0.08);
    // plot.getRangeAxis().setLowerBound(-0.08);
    decorateCategoryPlot(chart);/*www .j a  v a2  s  .  c  o m*/
    plot.setRangeGridlinesVisible(true);

    XYBarRenderer renderer = new XYBarRenderer() {

        private static final long serialVersionUID = 4168794048090452033L;

        @Override
        public Paint getItemPaint(int row, int column) {
            return ChartDecorator.COLOR_LIST.get(0);
        }
    };
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setBaseNegativeItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setShadowVisible(Boolean.FALSE);
    plot.setRenderer(renderer);

    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;/*  ww  w .  j  a  va 2 s  .co  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:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java

/**
 * Updates the axis-related properties of a plot.
 * //  w  w w  . j a v a 2  s  .  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:binky.reportrunner.ui.actions.admin.GetAuditChartAction.java

@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String execute() throws Exception {

    // do some stuff and get a chart going
    // DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    List<RunnerHistoryEvent> events = auditService.getSuccessEvents(module, new Date(fromDate),
            new Date(toDate));
    Map<String, TimeSeries> serieses = new HashMap<String, TimeSeries>();
    for (RunnerHistoryEvent e : events) {
        TimeSeries s = serieses.get(e.getMethod());
        if (s == null) {
            s = new TimeSeries(e.getMethod());
            serieses.put(e.getMethod(), s);
        }//from  w  w w  . j a v  a 2s .  c om
        s.addOrUpdate(new Millisecond(e.getTimeStamp()), e.getRunTime());
    }
    for (TimeSeries s : serieses.values()) {
        dataSet.addSeries(s);
    }
    chart = ChartFactory.createTimeSeriesChart(module, "", "run time (ms)", dataSet, true, false, false);

    // .createLineChart("","","Run Time (ms)",dataSet,PlotOrientation.VERTICAL,
    // true,false,false);
    XYPlot linePlot = (XYPlot) chart.getPlot();
    linePlot.setDomainGridlinesVisible(true);
    linePlot.setRangeGridlinesVisible(true);
    linePlot.setRangeGridlinePaint(Color.black);
    linePlot.setDomainGridlinePaint(Color.black);
    TextTitle subTitle = new TextTitle("Successful Executions");
    subTitle.setFont(new Font("Arial", Font.ITALIC, 10));
    chart.addSubtitle(subTitle);
    chart.getTitle().setFont(new Font("Arial", Font.BOLD, 12));

    DateAxis axis = (DateAxis) linePlot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy"));

    XYItemRenderer r = linePlot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    chart.setAntiAlias(true);
    chart.setTextAntiAlias(true);
    return SUCCESS;
}

From source file:com.rapidminer.gui.viewer.metadata.model.NumericalAttributeStatisticsModel.java

/**
 * Creates the histogram chart.//w w w .  j  ava  2  s.c  om
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(ExampleSet exampleSet) {
    JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet),
            PlotOrientation.VERTICAL, false, false, false);
    AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
    chart.setBackgroundPaint(null);
    chart.setBackgroundImageAlpha(0.0f);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setOutlineVisible(false);
    plot.setRangeZeroBaselineVisible(false);
    plot.setDomainZeroBaselineVisible(false);
    plot.setBackgroundPaint(COLOR_INVISIBLE);
    plot.setBackgroundImageAlpha(0.0f);

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL));
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    return chart;
}