Example usage for org.jfree.chart.renderer.xy XYItemRenderer setBasePositiveItemLabelPosition

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setBasePositiveItemLabelPosition

Introduction

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

Prototype

public void setBasePositiveItemLabelPosition(ItemLabelPosition position);

Source Link

Document

Sets the base positive item label position.

Usage

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    JFreeChart jfreechart = ChartFactory.createBubbleChart("Bubble Chart Demo 2", "X", "Y", xyzdataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setRenderer(new XYBubbleRenderer(0));
    xyplot.setForegroundAlpha(0.65F);/*from www .  ja  va  2  s.  c  om*/
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(0, Color.blue);
    xyitemrenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    xyitemrenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    xyitemrenderer.setBaseItemLabelsVisible(true);
    xyitemrenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setRange(0.0D, 10D);
    NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis();
    numberaxis1.setRange(0.0D, 10D);
    return jfreechart;
}

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:org.locationtech.udig.processingtoolbox.tools.BubbleChartDialog.java

private void updateChart(SimpleFeatureCollection features, String xField, String yField, String sizeField) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);/*from   w w w. ja  v a2 s . c  om*/
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setForegroundAlpha(0.75f);

    // 2. Setup Scatter plot
    // Create the bubble chart data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];
    NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYItemRenderer plotRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    plotRenderer.setSeriesPaint(0, java.awt.Color.ORANGE); // dot
    plotRenderer.setBaseItemLabelGenerator(new BubbleXYItemLabelGenerator());
    plotRenderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    plotRenderer
            .setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));

    // Set the bubble chart data, renderer, and axis into plot
    plot.setDataset(0, getBubbleChartData(features, xField, yField, sizeField));

    xPlotAxis.setAutoRangeIncludesZero(false);
    xPlotAxis.setAutoRange(false);
    double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX();
    double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX();
    double gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX());
    } else {
        xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap);
    }

    yPlotAxis.setAutoRangeIncludesZero(false);
    yPlotAxis.setAutoRange(false);
    differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY();
    differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY();
    gap = Math.abs(differUpper - differLower);
    if (differUpper > differLower) {
        yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY());
    } else {
        yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap);
    }

    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY);
    lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY);

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);

    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    // AverageY
    XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$
    horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY());
    horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY());
    lineDataset.addSeries(horizontal);

    // AverageX
    XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound());
    vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound());
    lineDataset.addSeries(vertical);

    plot.setDataset(1, lineDataset);
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);

    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot
    selectionRenderer.setSeriesOutlinePaint(0, java.awt.Color.RED);

    plot.setDataset(2, new DefaultXYZDataset2());
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}