Example usage for org.jfree.chart.annotations XYBoxAnnotation XYBoxAnnotation

List of usage examples for org.jfree.chart.annotations XYBoxAnnotation XYBoxAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.annotations XYBoxAnnotation XYBoxAnnotation.

Prototype

public XYBoxAnnotation(double x0, double y0, double x1, double y1, Stroke stroke, Paint outlinePaint,
        Paint fillPaint) 

Source Link

Document

Creates a new annotation.

Usage

From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java

private void setupGaps(GapSkipTracker gapTracker, DateAxis dateAxis, XYPlot plot) {
    if (gapTracker.gaps.isEmpty())
        return;//from  w  w w  .  j  a v  a  2s.com

    SegmentedTimeline timeline = new SegmentedTimeline(1000, 100, 0);
    timeline.setStartTime(gapTracker.leftEnd);

    for (Span gap : gapTracker.gaps) {
        timeline.addException(gap.start + GAP_SPACING, gap.end - 1000);

        long annotationX = gap.start + GAP_SPACING / 2;
        plot.addAnnotation(new XYLineAnnotation(annotationX, VERT_LINE_MIN_Y, annotationX, VERT_LINE_MAX_Y,
                GAP_STROKE, Color.darkGray));

        double boxW = GAP_SPACING * 0.4;
        XYBoxAnnotation box = new XYBoxAnnotation(annotationX - boxW, VERT_LINE_MIN_Y, annotationX + boxW,
                VERT_LINE_MAX_Y, null, null, null);
        String toolTip = resources.format("No_Activity_FMT", gap.getStart(), gap.getEnd());
        box.setToolTipText(toolTip);
        plot.addAnnotation(box);
    }

    dateAxis.setTimeline(timeline);
}

From source file:com.juanhg.icecubes.IceCubesApplet.java

private void drawGlass() {
    Stroke border = new BasicStroke(3f);

    gBaseAnnotation = new XYShapeAnnotation(new Ellipse2D.Double(gXLeft, gYBase - 0.5, gXRight - gXLeft, 1),
            border, Color.BLACK, fluidColor);
    chartGlass.setAnnotation(gBaseAnnotation);

    gTopAnnotation = new XYShapeAnnotation(new Ellipse2D.Double(gXLeft, gYTop - 0.5, gXRight - gXLeft, 1),
            border, Color.BLACK);
    chartGlass.setAnnotation(gTopAnnotation);

    gRightAnnotation = new XYLineAnnotation(gXRight, gYBase, gXRight, gYTop, border, Color.black);
    chartGlass.setAnnotation(gRightAnnotation);

    gLeftAnnotation = new XYLineAnnotation(gXLeft, gYBase, gXLeft, gYTop, border, Color.black);
    chartGlass.setAnnotation(gLeftAnnotation);

    gTopAnnotation = new XYBoxAnnotation(gXLeft, gYBase, gXRight, gYTop / 2, null, null, fluidColor);
    chartGlass.setAnnotation(gTopAnnotation);

    updateGlass(IceCubesModel.getV(sliderVol.getValue(), sliderN.getValue()));

}

From source file:com.juanhg.icecubes.IceCubesApplet.java

private void updateGlass(double vol) {
    double surface = vol;
    Stroke border = new BasicStroke(3f);

    chartGlass.deleteAnnotation(gBaseAnnotation);
    gBaseAnnotation = new XYShapeAnnotation(new Ellipse2D.Double(gXLeft, gYBase - 0.5, gXRight - gXLeft, 1),
            border, Color.BLACK, fluidColor);
    chartGlass.setAnnotation(gBaseAnnotation);

    chartGlass.deleteAnnotation(gTopAnnotation);
    gTopAnnotation = new XYBoxAnnotation(gXLeft, gYBase, gXRight, surface, null, null, fluidColor);
    chartGlass.setAnnotation(gTopAnnotation);

    chartGlass.deleteAnnotation(gSurfaceAnnotation);
    gSurfaceAnnotation = new XYShapeAnnotation(
            new Ellipse2D.Double(gXLeft, (surface) - 0.5, gXRight - gXLeft, 1), border, Color.BLACK,
            fluidColor);//from w ww  . j a  v a2 s  .  c o  m
    chartGlass.setAnnotation(gSurfaceAnnotation);

    chartGlass.deleteAnnotation(cube1Annotation);
    chartGlass.deleteAnnotation(cube2Annotation);
    chartGlass.deleteAnnotation(cube3Annotation);
    chartGlass.deleteAnnotation(cube4Annotation);

    if (sliderVol.getValue() >= 10 || N <= 2) {
        if (N >= 1) {

            cube1Annotation = new XYShapeAnnotation(
                    new RoundRectangle2D.Double(cX, surface - 2, getCubeW(), getCubeH(), archeight, archwidth),
                    border, Color.BLACK, cubeColor);
            chartGlass.setAnnotation(cube1Annotation);

            if (N >= 2) {

                cube2Annotation = new XYShapeAnnotation(new RoundRectangle2D.Double(cX + getCubeW() + 0.4,
                        surface - 2, getCubeW(), getCubeH(), archeight, archwidth), border, Color.BLACK,
                        cubeColor);
                chartGlass.setAnnotation(cube2Annotation);

                if (N >= 3) {

                    cube3Annotation = new XYShapeAnnotation(new RoundRectangle2D.Double(cX,
                            surface - 2.2 - getCubeH(), getCubeW(), getCubeH(), archeight, archwidth), border,
                            Color.BLACK, cubeColor);
                    chartGlass.setAnnotation(cube3Annotation);

                    if (N >= 4) {

                        cube4Annotation = new XYShapeAnnotation(
                                new RoundRectangle2D.Double(cX + getCubeW() + 0.4, surface - 2.2 - getCubeH(),
                                        getCubeW(), getCubeH(), archeight, archwidth),
                                border, Color.BLACK, cubeColor);
                        chartGlass.setAnnotation(cube4Annotation);
                    }
                }
            }
        }
    } else {
        if (N >= 1) {

            cube1Annotation = new XYShapeAnnotation(
                    new RoundRectangle2D.Double(cX, gYBase, getCubeW(), getCubeH(), archeight, archwidth),
                    border, Color.BLACK, cubeColor);
            chartGlass.setAnnotation(cube1Annotation);

            if (N >= 2) {

                cube2Annotation = new XYShapeAnnotation(new RoundRectangle2D.Double(cX + getCubeW() + 0.4,
                        gYBase, getCubeW(), getCubeH(), archeight, archwidth), border, Color.BLACK, cubeColor);
                chartGlass.setAnnotation(cube2Annotation);

                if (N >= 3) {

                    cube3Annotation = new XYShapeAnnotation(new RoundRectangle2D.Double(cX, gYBase + getCubeH(),
                            getCubeW(), getCubeH(), archeight, archwidth), border, Color.BLACK, cubeColor);
                    chartGlass.setAnnotation(cube3Annotation);

                    if (N >= 4) {

                        cube4Annotation = new XYShapeAnnotation(
                                new RoundRectangle2D.Double(cX + getCubeW() + 0.4, gYBase + getCubeH(),
                                        getCubeW(), getCubeH(), archeight, archwidth),
                                border, Color.BLACK, cubeColor);
                        chartGlass.setAnnotation(cube4Annotation);
                    }
                }
            }
        }
    }
}

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

/**
 * Update the plot./* w ww .  ja v  a2s .  co m*/
 */
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);
}

From source file:ch.algotrader.client.chart.ChartTab.java

@SuppressWarnings("unchecked")
public void updateData(ChartDataVO chartData) {

    resetAxis();// w ww.  java 2 s  .  c  o  m

    // add/update indicators
    for (IndicatorVO indicator : chartData.getIndicators()) {

        RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime());
        TimeSeries series = this.indicators.get(indicator.getName());

        if (series != null) {
            series.addOrUpdate(timePeriod, indicator.getValue());
        }
    }

    // add/update bars
    for (BarVO bar : chartData.getBars()) {

        OHLCSeries series = this.bars.get(bar.getSecurityId());

        if (series != null) {

            // remove a value if it already exists
            RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime());
            if (series.indexOf(timePeriod) >= 0) {
                series.remove(timePeriod);
            }
            series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(),
                    bar.getLow().doubleValue(), bar.getClose().doubleValue());
        }
    }

    // make all invisible since they might not currently have a value
    for (Marker marker : this.markers.values()) {
        marker.setAlpha(0);
    }

    // update markers
    for (MarkerVO markerVO : chartData.getMarkers()) {

        Marker marker = this.markers.get(markerVO.getName());
        Boolean selected = this.markersSelectionStatus.get(markerVO.getName());
        String name = marker.getLabel().split(":")[0];
        if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) {

            ValueMarker valueMarker = (ValueMarker) marker;
            ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO;
            valueMarker.setValue(valueMarkerVO.getValue());
            marker.setLabel(name + ": " + valueMarkerVO.getValue());
            marker.setAlpha(selected ? 1.0f : 0.0f);

        } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO;
            intervalMarker.setStartValue(intervalMarkerVO.getStartValue());
            intervalMarker.setEndValue(intervalMarkerVO.getEndValue());
            marker.setLabel(
                    name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue());
            marker.setAlpha(selected ? 0.5f : 0.0f);

        } else {
            throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass());
        }
    }

    // update annotations
    for (AnnotationVO annotationVO : chartData.getAnnotations()) {

        AbstractXYAnnotation annotation;
        if (annotationVO instanceof PointerAnnotationVO) {

            PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO;
            XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(),
                    pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(),
                    3.926990816987241D);
            pointerAnnotation.setTipRadius(0);
            pointerAnnotation.setBaseRadius(20);
            pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
            pointerAnnotation.setFont(new Font("SansSerif", 0, 9));
            pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime())
                    + "<br>" + pointerAnnotationVO.getValue() + "</html>");

            annotation = pointerAnnotation;

        } else if (annotationVO instanceof BoxAnnotationVO) {

            BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO;
            XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(),
                    boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(),
                    boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60));
            boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - "
                    + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>"
                    + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>");

            annotation = boxAnnotation;
        } else {
            throw new RuntimeException("unkown annotation type" + annotationVO.getClass());
        }

        if (!getPlot().getAnnotations().contains(annotation)) {
            getPlot().addAnnotation(annotation);
        }
    }

    // update description
    for (Title title : (List<Title>) this.getChart().getSubtitles()) {
        if (title instanceof TextTitle) {
            TextTitle textTitle = ((TextTitle) title);
            if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) {
                textTitle.setText(chartData.getDescription());
                textTitle.setVisible(true);
            } else {
                textTitle.setVisible(false);
            }
        }
    }

    initAxis();
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Breakdowns", "Production Date",
            "Hours of Operation", xydataset, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesShape(0, new Rectangle(2, 2));
    xylineandshaperenderer.setSeriesShape(1, new Rectangle(2, 2));
    xylineandshaperenderer.setBaseLinesVisible(false);
    xylineandshaperenderer.setBaseShapesFilled(true);
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseToolTipGenerator(null);
    xylineandshaperenderer.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer.setSeriesPaint(1, Color.red);
    xyplot.setDomainGridlineStroke(new BasicStroke(1.0F));
    xyplot.setRangeGridlineStroke(new BasicStroke(1.0F));
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setTickUnit(new NumberTickUnit(50000D));
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM.yy"));
    dateaxis.setVerticalTickLabels(true);
    Color color = new Color(255, 0, 0, 60);
    Color color1 = new Color(0, 255, 0, 60);
    XYBoxAnnotation xyboxannotation = new XYBoxAnnotation((new Day(1, 1, 2004)).getMiddleMillisecond(), 0.0D,
            (new Day(31, 1, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 2.9");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 2, 2004)).getMiddleMillisecond(), 0.0D,
            (new Day(29, 2, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 2.5");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 5, 2004)).getMiddleMillisecond(), 50000D,
            (new Day(31, 5, 2004)).getMiddleMillisecond(), 100000D, new BasicStroke(0.0F), color, color);
    xyboxannotation.setToolTipText("Value: 1.8");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    xyboxannotation = new XYBoxAnnotation((new Day(1, 6, 2005)).getMiddleMillisecond(), 0.0D,
            (new Day(30, 6, 2005)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color1, color1);
    xyboxannotation.setToolTipText("Value: 3.7");
    xylineandshaperenderer.addAnnotation(xyboxannotation);
    return jfreechart;
}