Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseItemLabelPaint

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseItemLabelPaint

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseItemLabelPaint.

Prototype

public void setBaseItemLabelPaint(Paint paint) 

Source Link

Document

Sets the base item label paint and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java

public synchronized void addLabelledPeakDataset(final XYDataset dataSet, final String label) {

    // Add standard peak data set.
    addPeakDataset(dataSet);/*from   w  ww.  j a va  2 s  . c  o m*/

    // Do we have a label?
    if (label != null && label.length() > 0) {

        // Add peak label renderer and data set.
        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, false);
        renderer.setBaseItemLabelsVisible(labelsVisible == 2);
        renderer.setBaseItemLabelPaint(LABEL_COLOR);
        addDataSetRenderer(dataSet, renderer);
        renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {

            @Override
            public String generateLabel(final XYDataset xyDataSet, final int series, final int item) {

                return ((PeakDataSet) xyDataSet).isPeak(item) ? label : null;
            }
        });

        numOfPeaks++;
        havePeakLabels = true;
    }
}

From source file:guineu.modules.filter.Alignment.RANSAC.AlignmentRansacPlot.java

public AlignmentRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);/*from   w  ww . ja  v  a 2  s  .  c  om*/

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    //     legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

From source file:net.sf.mzmine.modules.peaklistmethods.alignment.ransac.AlignmentRansacPlot.java

public AlignmentRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);/*from  w w  w .j a  v  a2  s . co  m*/

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.AlignmentGCGCRansacPlot.java

public AlignmentGCGCRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);//from   ww  w.jav  a  2  s  . c om

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    //     legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

private void configureRenderer(ChromatogramPlotDataSet dataset, int datasetIndex) {

    final XYPlot plot = chartNode.getChart().getXYPlot();

    XYLineAndShapeRenderer newRenderer = new XYLineAndShapeRenderer();
    final int lineThickness = dataset.getLineThickness();
    newRenderer.setBaseShape(new Ellipse2D.Double(-2 * lineThickness, -2 * lineThickness, 4 * lineThickness + 1,
            4 * lineThickness + 1));// w ww . j  av  a 2 s .  co m
    newRenderer.setBaseShapesFilled(true);
    newRenderer.setBaseShapesVisible(dataset.getShowDataPoints());
    newRenderer.setDrawOutlines(false);

    Stroke baseStroke = new BasicStroke(lineThickness);
    newRenderer.setBaseStroke(baseStroke);

    // Set tooltips for legend
    newRenderer.setLegendItemToolTipGenerator((ds, series) -> {
        if (ds instanceof ChromatogramPlotDataSet) {
            return ((ChromatogramPlotDataSet) ds).getDescription();
        } else
            return null;
    });

    // Set color
    Color baseColor = dataset.getColor();
    newRenderer.setBasePaint(JavaFXUtil.convertColorToAWT(baseColor));

    // Set label generator
    XYItemLabelGenerator intelligentLabelGenerator = new IntelligentItemLabelGenerator(chartNode, 100, dataset);
    newRenderer.setBaseItemLabelGenerator(intelligentLabelGenerator);
    newRenderer.setBaseItemLabelPaint(JavaFXUtil.convertColorToAWT(labelsColor));
    newRenderer.setBaseItemLabelsVisible(itemLabelsVisible.get());
    newRenderer.setBaseItemLabelsVisible(true);

    // Set tooltip generator
    newRenderer.setBaseToolTipGenerator(dataset);

    plot.setRenderer(datasetIndex, newRenderer);

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYDataset dataset = (XYDataset) datasets.getDatasets().get("1");

    final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend,
            false, false);/* w  ww . ja va2  s  . c om*/
    sparkLineGraph.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    sparkLineGraph.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        sparkLineGraph.addSubtitle(subTitle);
    }

    sparkLineGraph.setBorderVisible(false);
    sparkLineGraph.setBorderPaint(Color.BLACK);
    XYPlot plot = sparkLineGraph.getXYPlot();
    plot.setOutlineVisible(false);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(color);

    // calculate the last marker color
    Paint colorLast = getLastPointColor();

    // Calculate average, minimum and maximum to draw plot borders.
    boolean isFirst = true;
    double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY;
    int count = 0;
    for (int i = 0; i < timeSeries.getItemCount(); i++) {
        if (timeSeries.getValue(i) != null) {
            count++;
            if (isFirst) {
                min = timeSeries.getValue(i).doubleValue();
                max = timeSeries.getValue(i).doubleValue();
                isFirst = false;
            }
            double n = timeSeries.getValue(i).doubleValue();
            //calculate avg, min, max
            avg += n;
            if (n < min)
                min = n;
            if (n > max)
                max = n;
        }
    }
    // average
    avg = avg / (double) count;

    // calculate min and max between thresholds!
    boolean isFirst2 = true;
    double lb = 0, ub = 0;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        if (isFirst2 == true) {
            ub = thres.doubleValue();
            lb = thres.doubleValue();
            isFirst2 = false;
        }
        if (thres.doubleValue() > ub)
            ub = thres.doubleValue();
        if (thres.doubleValue() < lb)
            lb = thres.doubleValue();
    }

    plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2));

    addMarker(1, avg, Color.GRAY, 0.8f, plot);
    //addAvaregeSeries(series, plot);
    addPointSeries(timeSeries, plot);

    int num = 3;
    for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
        Double thres = (Double) iterator.next();
        TargetThreshold targThres = thresholds.get(thres);
        Color color = Color.WHITE;
        if (targThres != null && targThres.getColor() != null) {
            color = targThres.getColor();
        }
        if (targThres.isVisible()) {
            addMarker(num++, thres.doubleValue(), color, 0.5f, plot);
        }
    }

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0.2);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);

    plot.getRenderer().setSeriesPaint(0, Color.BLACK);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        public boolean getItemShapeVisible(int _series, int item) {
            TimeSeriesDataItem tsdi = timeSeries.getDataItem(item);
            if (tsdi == null)
                return false;
            Month period = (Month) tsdi.getPeriod();
            int currMonth = period.getMonth();
            int currYear = period.getYearValue();
            int lastMonthFilled = lastMonth.getMonth();
            int lastYearFilled = lastMonth.getYearValue();
            boolean isLast = false;
            if (currYear == lastYearFilled && currMonth == lastMonthFilled) {
                isLast = true;
            }
            return isLast;
        }
    };
    renderer.setSeriesPaint(0, Color.decode("0x000000"));

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(colorLast);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setUseOutlinePaint(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0));

    if (wlt_mode.doubleValue() == 0) {
        renderer.setBaseItemLabelsVisible(Boolean.FALSE, true);
    } else {
        renderer.setBaseItemLabelsVisible(Boolean.TRUE, true);
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
        renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"),
                new DecimalFormat("0.###")) {
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0)
                    return "";
                String columnKey = (String) dataset.getColumnKey(column);
                int separator = columnKey.indexOf('-');
                String month = columnKey.substring(0, separator);
                String year = columnKey.substring(separator + 1);
                int monthNum = Integer.parseInt(month);
                if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) {
                    if (wlt_mode.doubleValue() == 2 && column % 2 == 0)
                        return "";

                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.MONTH, monthNum - 1);
                    SimpleDateFormat dataFormat = new SimpleDateFormat("MMM");
                    return dataFormat.format(calendar.getTime());
                } else
                    return "" + monthNum;
            }
        });
    }

    if (wlt_mode.doubleValue() == 3) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2));

    } else if (wlt_mode.doubleValue() == 4) {
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4));
    }

    if (legend == true) {
        LegendItemCollection collection = createThresholdLegend(plot);
        LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage);
        collection.add(item);
        plot.setFixedLegendItems(collection);

    }

    plot.setRenderer(0, renderer);
    logger.debug("OUT");
    return sparkLineGraph;
}