Example usage for org.jfree.chart.renderer.xy XYBubbleRenderer setBaseToolTipGenerator

List of usage examples for org.jfree.chart.renderer.xy XYBubbleRenderer setBaseToolTipGenerator

Introduction

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

Prototype

@Override
public void setBaseToolTipGenerator(XYToolTipGenerator generator) 

Source Link

Document

Sets the base tool tip generator and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:probe.com.view.core.chart4j.VennDiagramPanel.java

/**
 * Update the plot./*  w w w  .java2s  .  c om*/
 */
public void updatePlot() {

    //        plotPanel.removeAll();
    tooltipToDatasetMap = new HashMap<String, String>();

    DefaultXYZDataset xyzDataset = new DefaultXYZDataset();

    chart = ChartFactory.createBubbleChart(null, "X", "Y", xyzDataset, PlotOrientation.VERTICAL, false, true,
            false);
    XYPlot plot = chart.getXYPlot();

    if (currentVennDiagramType == VennDiagramType.ONE_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) {
        plot.getRangeAxis().setRange(0.86, 1.24);
        plot.getDomainAxis().setRange(0.85, 1.25);
    } else {
        plot.getRangeAxis().setRange(-0.04, 0.6);
        plot.getDomainAxis().setRange(-0.08, 0.7);
    }

    plot.getRangeAxis().setVisible(false);
    plot.getDomainAxis().setVisible(false);

    double radius = 0.1;
    Ellipse2D ellipse = new Ellipse2D.Double(1 - radius, 1 - radius, radius + radius, radius + radius);
    XYShapeAnnotation xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f),
            new Color(140, 140, 140, 150), datasetAColor); // @TODO: make it possible set the line color and width?
    plot.addAnnotation(xyShapeAnnotation);

    if (currentVennDiagramType == VennDiagramType.TWO_WAY
            || currentVennDiagramType == VennDiagramType.THREE_WAY) {
        ellipse = new Ellipse2D.Double(1 - radius + 0.1, 1 - radius, radius + radius, radius + radius);
        xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150),
                datasetBColor);
        plot.addAnnotation(xyShapeAnnotation);
    }

    if (currentVennDiagramType == VennDiagramType.THREE_WAY) {
        ellipse = new Ellipse2D.Double(1 - radius + 0.05, 1 - radius + 0.1, radius + radius, radius + radius);
        xyShapeAnnotation = new XYShapeAnnotation(ellipse, new BasicStroke(2f), new Color(140, 140, 140, 150),
                datasetCColor);
        plot.addAnnotation(xyShapeAnnotation);
    }

    XYTextAnnotation anotation;

    if (currentVennDiagramType == VennDiagramType.ONE_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 1.0, 1.0);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.TWO_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 1.0);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 1.0);
        anotation.setToolTipText(groupNames.get("b"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 1.0);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(),
                    legendDatasetBThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.THREE_WAY) {

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.96, 0.97);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 1.14, 0.97);
        anotation.setToolTipText(groupNames.get("b"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 1.05, 0.97);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 1.05, 1.14);
        anotation.setToolTipText(groupNames.get("c"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "c");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.99, 1.065);
        anotation.setToolTipText(
                "<html>" + groupNames.get("a") + "  &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ac");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 1.11, 1.065);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 1.05, 1.036);
        anotation.setToolTipText("<html>" + groupNames.get("a") + "  &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abc");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAThreeWay.getX(),
                    legendDatasetAThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBThreeWay.getX(),
                    legendDatasetBThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCThreeWay.getX(),
                    legendDatasetCThreeWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }

    } else if (currentVennDiagramType == VennDiagramType.FOUR_WAY) {

        XYBoxAnnotation anotation2 = new XYBoxAnnotation(0, 0, 0.2, 0.5, new BasicStroke(2), Color.LIGHT_GRAY,
                datasetAColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0.1, 0, 0.3, 0.4, new BasicStroke(2), Color.LIGHT_GRAY, datasetBColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0, 0.1, 0.4, 0.3, new BasicStroke(2), Color.LIGHT_GRAY, datasetCColor);
        plot.addAnnotation(anotation2);

        anotation2 = new XYBoxAnnotation(0, 0, 0.5, 0.2, new BasicStroke(2), Color.LIGHT_GRAY, datasetDColor);
        plot.addAnnotation(anotation2);

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("a").size(), 0.15, 0.45);
        anotation.setToolTipText(groupNames.get("a"));
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "a");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ab").size(), 0.15, 0.35);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ab");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abc").size(), 0.15, 0.25);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abcd").size(), 0.15, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("c") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abcd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("abd").size(), 0.15, 0.05);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("b")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "abd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ac").size(), 0.05, 0.25);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ac");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("acd").size(), 0.05, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("c")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "acd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("ad").size(), 0.05, 0.05);
        anotation
                .setToolTipText("<html>" + groupNames.get("a") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "ad");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("b").size(), 0.25, 0.35);
        anotation.setToolTipText("<html>" + groupNames.get("b") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "b");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bc").size(), 0.25, 0.25);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bc");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bcd").size(), 0.25, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("c")
                + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bcd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("bd").size(), 0.25, 0.05);
        anotation
                .setToolTipText("<html>" + groupNames.get("b") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "bd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("c").size(), 0.35, 0.25);
        anotation.setToolTipText("<html>" + groupNames.get("c") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "c");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("cd").size(), 0.35, 0.15);
        anotation
                .setToolTipText("<html>" + groupNames.get("c") + " &#8745; " + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "cd");

        anotation = new XYTextAnnotation("" + vennDiagramResults.get("d").size(), 0.45, 0.15);
        anotation.setToolTipText("<html>" + groupNames.get("d") + "</html>");
        anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeValues));
        plot.addAnnotation(anotation);
        tooltipToDatasetMap.put(anotation.getToolTipText(), "d");

        // legend
        if (showLegend) {
            anotation = new XYTextAnnotation(groupNames.get("a"), legendDatasetAFourWay.getX(),
                    legendDatasetAFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("b"), legendDatasetBFourWay.getX(),
                    legendDatasetBFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("c"), legendDatasetCFourWay.getX(),
                    legendDatasetCFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
            anotation = new XYTextAnnotation(groupNames.get("d"), legendDatasetDFourWay.getX(),
                    legendDatasetDFourWay.getY());
            anotation.setTextAnchor(TextAnchor.BASELINE_LEFT);
            anotation.setFont(new Font(anotation.getFont().getFontName(), Font.BOLD, fontSizeLegend));
            plot.addAnnotation(anotation);
        }
    }

    // set up the renderer
    XYBubbleRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    plot.setRenderer(renderer);

    // make all datapoints semitransparent
    plot.setForegroundAlpha(0.5f);

    // remove space before/after the domain axis
    plot.getDomainAxis().setUpperMargin(0);
    plot.getDomainAxis().setLowerMargin(0);

    plot.setRangeGridlinePaint(Color.black);

    // hide unwanted chart details
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    chart.getPlot().setOutlineVisible(false);

    // set background color
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setBackgroundPaint(Color.WHITE);
    chartPanel = new ChartPanel(chart);

    // disable the pop up menu
    chartPanel.setPopupMenu(null);

    chartPanel.setBackground(Color.WHITE);

    // add the plot to the chart
    //        plotPanel.add(chartPanel);
    //        plotPanel.revalidate();
    //        plotPanel.repaint();
    //
    //      this.add(plotPanel);
}