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:com.rapidminer.gui.viewer.metadata.model.NumericalAttributeStatisticsModel.java

/**
 * Creates the histogram chart.//w  ww .j  a va2 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;
}

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.EICPlot.java

public EICPlot(List<List<NavigableMap<Double, Double>>> clusters, List<Double> colors, List<List<String>> info,
        List<NavigableMap<Double, Double>> modelPeaks) {
    super(null, true);

    setBackground(Color.white);//from ww w  .j av a2 s.c om
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberAxis xAxis = new NumberAxis("Retention Time");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    NumberAxis yAxis = new NumberAxis("Intensity");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    xyDataset = new XYSeriesCollection();
    colorDataset = new ArrayList<>();
    toolTips = new ArrayList<>();

    int seriesID = 0;

    for (int i = 0; i < clusters.size(); ++i) {
        List<NavigableMap<Double, Double>> cluster = clusters.get(i);
        double color = colors.get(i);

        for (int j = 0; j < cluster.size(); ++j) {
            XYSeries series = new XYSeries(seriesID++);

            for (Entry<Double, Double> e : cluster.get(j).entrySet())
                series.add(e.getKey(), e.getValue());

            xyDataset.addSeries(series);
            colorDataset.add(color);
            toolTips.add(info.get(i).get(j));
        }
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
        @Override
        public Paint getItemPaint(int row, int col) {
            double c = colorDataset.get(row);
            return Color.getHSBColor((float) c, 1.0f, 1.0f);
        }
    };

    renderer.setDefaultShapesVisible(false);
    renderer.setDefaultToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                return toolTips.get(series);
            } catch (NullPointerException | IndexOutOfBoundsException e) {
                return "";
            }
        }
    });

    XYPlot plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false);
    chart.setBackgroundPaint(Color.white);

    super.setChart(chart);
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.HistogramPlot.java

/** 
 * Creates the chart./*from  w  w  w  .j a v a 2  s.  com*/
 * @see ChartObject#createChar()
 */
void createChart() {
    HistogramBarRenderer renderer = new HistogramBarRenderer(colours);
    for (int i = 0; i < colours.size(); i++)
        renderer.setSeriesPaint(i, colours.get(i));
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.ScatterPlot.java

/** 
 * Creates the chart./*from w  ww.ja v  a2 s.  c  o m*/
 * @see ChartObject#createChar()
 */
void createChart() {
    PointRenderer renderer = new PointRenderer(colours, shapes);
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    if (backgroundImage != null) {
        plot.setRangeGridlinesVisible(false);
        plot.setDomainGridlinesVisible(false);
        plot.setBackgroundImage(backgroundImage);
    }
    chart = new JFreeChart(title, plot);
}

From source file:Chart.JFreeChartDemo.java

/**
 * Create a chart./* w  ww. jav  a2s. c o m*/
 *
 * @param dataset the dataset
 * @return the chart
 */
private JFreeChart createChart(XYDataset dataset) {

    //       WHAT IS THIS LINE???
    // JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, rootPaneCheckingEnabled, rootPaneCheckingEnabled, rootPaneCheckingEnabled)

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("", // chart title
            "Time", // domain axis label
            "Range", // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);

    // render shapes and lines
    //        XYLineAndShapeRenderer renderer =
    //                new XYLineAndShapeRenderer(true, true);
    //        plot.setRenderer(renderer);
    //        renderer.setBaseShapesVisible(true);
    //        renderer.setBaseShapesFilled(true);
    //
    //        // set the renderer's stroke
    //        Stroke stroke = new BasicStroke(
    //                3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    //        
    //        renderer.setBaseOutlineStroke(stroke);
    //       
    //Shape theshape = ShapeUtilities.createDiamond(1);
    //renderer.setSeriesShape(5, theshape);

    // label the points
    //        NumberFormat format = NumberFormat.getNumberInstance();
    //        format.setMaximumFractionDigits(2);
    //        XYItemLabelGenerator generator =
    //                new StandardXYItemLabelGenerator(
    //                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
    //                format, format);
    //        renderer.setBaseItemLabelGenerator(generator);
    //        renderer.setBaseItemLabelsVisible(true);

    return chart;
}

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

/**
 * @see Graph/*  w  w  w  .  j  ava2s . c o  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);

    final JFreeChart chart = new JFreeChart(null, new Font("SansSerif", Font.BOLD, 24), 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:edu.cudenver.bios.chartsvc.resource.ScatterPlotResource.java

/**
 * Create a JFreeChart object from the chart specification.  JFreechart provides 
 * functionality to render 2D scatter plots as jpeg images
 * // w  w  w  . j a  v  a 2s  .co m
 * @param chart chart specification object
 * @return JFreeChart object
 * @throws ResourceException
 */
private JFreeChart buildScatterPlot(Chart chart) throws ResourceException {
    ArrayList<LineStyle> lineStyleList = chart.getLineStyleList();

    float dashedLength = 1.0f;
    float spaceLength = 1.0f;
    float thickness = 1.0f;

    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;

    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }
        }

        if (seriesIdx >= 0 && seriesIdx < lineStyleList.size()) {
            LineStyle lineStyle = lineStyleList.get(seriesIdx);
            dashedLength = (float) lineStyle.getDashLength();
            spaceLength = (float) lineStyle.getSpaceLength();
            thickness = (float) lineStyle.getWidth();
        } else {
            dashedLength = 1.0f;
            spaceLength = 1.0f;
            thickness = 1.0f;
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);

        if (seriesIdx >= 0) {
            /*rend.setSeriesStroke(seriesIdx, 
                  new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {(float) seriesIdx, (float) 2*seriesIdx}, 0.0f));*/
            rend.setSeriesStroke(seriesIdx, new BasicStroke(thickness, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND, 1.0f, new float[] { dashedLength, spaceLength }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    JFreeChart renderedChart = new JFreeChart(chart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    renderedChart.setBackgroundPaint(Color.WHITE);
    if (chart.hasLegend()) {
        LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
        legend.setFrame(BlockBorder.NONE);
        legend.setPosition(RectangleEdge.BOTTOM);
        renderedChart.addLegend(legend);
    }

    return renderedChart;
}

From source file:org.n52.io.measurement.img.ChartIoHandler.java

private void showGridlinesOnChart(XYPlot xyPlot) {
    boolean showGrid = getChartStyleDefinitions().isGrid();
    xyPlot.setDomainGridlinesVisible(showGrid);
    xyPlot.setRangeGridlinesVisible(showGrid);
}

From source file:no.ntnu.mmfplanner.ui.graph.NpvChart.java

/**
 * Updates the chart with data from the model.
 *///w  w w.j a  va2 s . c  o m
private void updateModel() {
    modelValid = true;

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0));
    renderer.setUseFillPaint(true);

    // the x=0 line
    addLineX(dataset, renderer);

    // rolling npv line (iterative)
    ProjectRoi projectRoi = ProjectRoi.getRoiTable(project, project.getInterestRate(), false);
    addNpvLine(projectRoi, "NPV Iterative", chartColor[0], dataset, renderer);

    // rolling npv line (waterfall)
    if (waterfall) {
        ProjectRoi projectRoiWaterfall = ProjectRoi.getRoiTable(project, project.getInterestRate(), true);
        addNpvLine(projectRoiWaterfall, "NPV Waterfall", chartColor[1], dataset, renderer);
    }

    // legend (break even and self funding)
    addLegendElements(dataset, renderer);

    XYPlot plot = ((XYPlot) getChart().getPlot());
    plot.setDataset(dataset);
    plot.setRenderer(renderer);

    plot.setDomainGridlinesVisible(false);
}

From source file:greenapi.ui.charts.ChartPanelSupport.java

/**
 * Clean the value of the chart./*from w w w.j  a v a  2 s  . com*/
 * 
 * @see #createChart()
 */
public void cleanChart() {
    this.chart.removeLegend();
    this.chartPanel.setBorder(null);

    cleanLabels();

    DateAxis localDateAxis = (DateAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    localDateAxis.setTickLabelsVisible(false);
    localDateAxis.setTickMarksVisible(false);
    localDateAxis.setAxisLineVisible(false);

    ValueAxis localValueAxis = ((XYPlot) this.chart.getPlot()).getRangeAxis();
    localValueAxis.setTickLabelsVisible(false);
    localValueAxis.setTickMarksVisible(false);
    localValueAxis.setAxisLineVisible(false);

    XYPlot localXYPlot = (XYPlot) this.chart.getPlot();
    localXYPlot.setDomainGridlineStroke(this.defaultLineStroke);
    localXYPlot.setDomainGridlinesVisible(true);
    localXYPlot.setRangeGridlineStroke(this.defaultLineStroke);
    localXYPlot.setRangeGridlinesVisible(true);

    localXYPlot.setAxisOffset(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D));
    localXYPlot.setInsets(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D), true);
}