Example usage for org.jfree.chart.block BlockBorder BlockBorder

List of usage examples for org.jfree.chart.block BlockBorder BlockBorder

Introduction

In this page you can find the example usage for org.jfree.chart.block BlockBorder BlockBorder.

Prototype

public BlockBorder(Paint paint) 

Source Link

Document

Creates a new border with the specified color.

Usage

From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotAirTemp, boolean plotWaterTemp,
        boolean plotDewpointTemp) throws ParseException {
    Date startTime = null;//from w w  w  .j a  v a  2 s.  com
    NumberPhenomenon aTemperature = null;
    NumberPhenomenon wTemperature = null;
    NumberPhenomenon dTemperature = null;
    // default setting
    ChartPlotter plotter = new ChartPlotter();
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");

    double minValue = 100;
    double maxValue = -100;
    int plotIndex = 0;
    if (plotAirTemp) {
        aTemperature = getLocationForecastDataModel().getPhenomenen(PhenomenonName.AirTemperature.toString(),
                NumberPhenomenon.class);
        minValue = aTemperature.getMinValue() < minValue ? aTemperature.getMinValue() : minValue;
        maxValue = aTemperature.getMaxValue() > maxValue ? aTemperature.getMaxValue() : maxValue;
        startTime = aTemperature.getTime().get(0);
        plotTemperature(plotter, aTemperature, new BasicStroke(2.0f), Color.RED,
                messages.getString("label.air"), true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(1, true);
        plotIndex++;
    }

    if (plotWaterTemp) {
        wTemperature = getOceanForecastDataModel().getPhenomenen(PhenomenonName.seaTemperature.toString(),
                NumberPhenomenon.class);
        // only plot water temperature if it is availbe for this location
        if (wTemperature != null) {
            minValue = wTemperature.getMinValue() < minValue ? wTemperature.getMinValue() : minValue;
            maxValue = wTemperature.getMaxValue() > maxValue ? wTemperature.getMaxValue() : maxValue;
            startTime = wTemperature.getTime().get(0);
            BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f);
            plotTemperature(plotter, wTemperature, dottedStroke, Color.RED, messages.getString("label.water"),
                    true);
            plotter.getPlot().getRenderer(plotIndex++).setSeriesVisibleInLegend(0, true);
        }
    }

    if (plotDewpointTemp) {
        dTemperature = getLocationForecastDataModel()
                .getPhenomenen(PhenomenonName.dewPointTemperature.toString(), NumberPhenomenon.class);
        minValue = dTemperature.getMinValue() < minValue ? dTemperature.getMinValue() : minValue;
        maxValue = dTemperature.getMaxValue() > maxValue ? dTemperature.getMaxValue() : maxValue;
        startTime = dTemperature.getTime().get(0);
        plotTemperature(plotter, dTemperature, new BasicStroke(2.0f), Color.ORANGE,
                messages.getString("label.dewpoint"), false);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
    }

    double tick = (maxValue - minValue) / 3.5;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(minValue / (tick)) * (tick);
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 7;

    // set range axis
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(Color.RED);
    numberAxis.setTickLabelPaint(Color.RED);
    numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)");
    numberAxis.setTickUnit(new NumberTickUnit(tick));
    numberAxis.setLowerBound(lowBound);
    numberAxis.setUpperBound(upperBound);

    //Set left axis and right axis
    plotter.getPlot().setRangeAxis(0, numberAxis);
    plotter.getPlot().setRangeAxis(1, numberAxis);
    //Set the third axis and hide the third axis
    if (plotAirTemp && plotWaterTemp && plotDewpointTemp) {
        NumberAxis numberAxis2 = new NumberAxis();
        numberAxis2.setTickUnit(new NumberTickUnit(tick));
        numberAxis2.setLowerBound(lowBound);
        numberAxis2.setUpperBound(upperBound);
        plotter.getPlot().setRangeAxis(2, numberAxis2);
        plotter.getPlot().getRangeAxis(2).setVisible(false);
    }

    //Show legend at the top right position of the plot
    LegendTitle lt = new LegendTitle(plotter.getPlot());
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(255, 255, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.TOP);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.95, lt, RectangleAnchor.TOP_RIGHT);
    plotter.getPlot().addAnnotation(ta);

    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // add markers
    plotter.addDomainMarkers(getShortTermTime(startTime), timezone, locale);
    Date minDate = getShortTermTime(startTime).get(0);
    Date maxDate = getShortTermTime(startTime).get(getShortTermTime(startTime).size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    plotter.getPlot().setOutlineVisible(true);
    // invisible the domain i.e, x axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);

    return plotter.getPlot();

}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapWorker.java

protected Void doInBackground() throws Exception {
    // this is a SwingWorker thread from its pool, give it a recognizable name
    Thread.currentThread().setName("PortHeatMapWorker");

    JFreeChart Chart = PlotPanel.getHeatChart();

    logger.info("Worker Building HeatMapPlot");
    MessageManager.getInstance()/*w  w  w .  j  av  a2  s  . co  m*/
            .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "Worker Building HeatMapPlot"));

    PortHeatMapDataSet pHeatMap = null;
    if (UseService) {
        SMT_UpdateService updateService = SMT_UpdateService.getInstance();
        History = updateService.getCollection();
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet(History, IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet(History, IncludedDepths);
    } else if (History != null) {
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet(History, IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet(History, IncludedDepths);
    } else {
        // FIXME - eliminate this, for test purposes only
        if (IncludedNodes != null)
            pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedNodes);
        else
            pHeatMap = new PortHeatMapDataSet("%h/scripts/OsmScripts/SmtScripts/sierra3H.his", IncludedDepths);
    }
    //    logger.fine("Finished creating dataset");
    //    logger.fine("Max X: " + pHeatMap.getMaximumXValue());
    //    logger.fine("Max Y: " + pHeatMap.getMaximumYValue());
    //    logger.fine("Max Z: " + pHeatMap.getMaximumZValue());
    //    
    // if any of these "maximum" values are illegal, stop here and return null
    if (!pHeatMap.isValid()) {
        logger.severe("Invalid HeatMap, check OMS Collection or Depth filter (empty or null)");
        MessageManager.getInstance().postMessage(new SmtMessage(SmtMessageType.SMT_MSG_SEVERE,
                "Invalid HeatMap, check OMS Collection or Depth filter (empty or null)"));
        PlotPanel.setHeatMapDataSet(null);
        return null;
    }

    PlotPanel.setHeatMapDataSet(pHeatMap);

    Range fixedXRange = new Range(0, pHeatMap.getMaximumXValue()); // time #
    Range fixedYRange = new Range(0, pHeatMap.getMaximumYValue()); // port #
    Range fixedZRange = new Range(0, pHeatMap.getMaximumZValue()); // % Util

    // there are 3 valid paint scales, 0, 1, & 2
    LookupPaintScale paintScale = PaintScaleFactory.getLookupPaintScale(1, 0, fixedZRange.getUpperBound(),
            fixedZRange.getUpperBound());
    ValueAxis paintAxis = PaintScaleFactory.getPaintScaleAxis(0, fixedZRange.getUpperBound(),
            PortHeatMapPlotPanel.UtilizationAxisLabel);

    BufferedImage image = HeatMapUtilities.createHeatMapImage(pHeatMap, paintScale);
    XYDataImageAnnotation ann = new XYDataImageAnnotation(image, fixedXRange.getLowerBound(),
            fixedYRange.getLowerBound(), fixedXRange.getUpperBound(), fixedYRange.getUpperBound(), true);
    XYPlot plot = (XYPlot) Chart.getPlot();
    plot.getRenderer().addAnnotation(ann, Layer.BACKGROUND);

    // finally, show the heatmap
    PaintScaleLegend psLegend = new PaintScaleLegend(paintScale, paintAxis);
    psLegend.setMargin(new RectangleInsets(3, 40, 3, 10));
    psLegend.setPosition(RectangleEdge.TOP); // location (within NORTH) of
                                             // heatmap legend
    psLegend.setAxisOffset(4.0);
    psLegend.setFrame(new BlockBorder(Color.GRAY));
    Chart.addSubtitle(psLegend);

    // fix the sliders ranges, and set them for the middle
    if ((pHeatMap != null) && (PlotPanel != null)) {
        PlotPanel.getTimeSlider().setMinimum((int) fixedXRange.getLowerBound());
        PlotPanel.getTimeSlider().setMaximum((int) fixedXRange.getUpperBound());
        PlotPanel.getTimeSlider().setValue((int) fixedXRange.getCentralValue());

        PlotPanel.getPortSlider().setMinimum((int) fixedYRange.getLowerBound());
        PlotPanel.getPortSlider().setMaximum((int) fixedYRange.getUpperBound());
        PlotPanel.getPortSlider().setValue((int) fixedYRange.getCentralValue());

        HeatMapDepthPanel hmdp = new HeatMapDepthPanel(pHeatMap);
        PlotPanel.replaceDepthPanel(hmdp);
    }
    return null;
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 * Initialize the graph/*from  w w w .  j  a  va  2s.c  o m*/
 */
private void initGraph() {

    this.series = new BasicSeries("FFT");
    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart graph = ChartFactory.createXYLineChart(null, // title
            "", // no x-axis label
            "", // no y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // no legend
            false, // no tooltips
            false // no URLs
    );

    graph.setBorderVisible(false);
    graph.setPadding(new RectangleInsets(-5, 0, 0, 0));
    graph.setBackgroundPaint(null);
    graph.setBackgroundImageAlpha(0.0f);
    graph.setAntiAlias(true);

    plot = (XYPlot) graph.getPlot();

    powerAxis = new PowerAxis();
    plot.setRangeAxis(powerAxis);

    frequencyAxis = new FrequencyAxis();
    frequencyAxis.setTickLabelInsets(new RectangleInsets(10, 0, 0, 0));
    plot.setDomainAxis(frequencyAxis);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, Common.EPIQ_GREEN);
        renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    }

    plot.setBackgroundAlpha(0.0f);
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // X-axis setup
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setVisible(true);
    plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1);
    plot.setDomainCrosshairVisible(false);
    plot.setDomainCrosshairPaint(new Color(46, 46, 46));

    // Y-axis setup
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setVisible(true);
    plot.getRangeAxis().setRange(-50, 70);
    plot.setRangeCrosshairVisible(false);

    markerAnnotation.setVisible(false);
    plot.addAnnotation(markerAnnotation);
    plot.addAnnotation(markerTextAnnotation);

    this.markerTitle.setFont(new Font("Tahoma", Font.BOLD, 12));
    this.markerTitle.setFrame(new BlockBorder(new Color(46, 46, 46)));
    this.markerTitle.setBackgroundPaint(new Color(200, 200, 255, 100));
    this.markerTitle.setText("");
    this.markerTitle.setPadding(5, 15, 5, 15);
    this.markerTitle.setExpandToFitSpace(false);
    this.markerTitle.setBounds(new Rectangle2D.Double(0, 0, 100, 30));

    chartPanel = new ChartPanel(graph, false);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMouseZoomable(true);
    chartPanel.setOpaque(false);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            markerLocked = !markerLocked;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            updateMouseMarker(event);
        }

    });

    chartPanel.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (!markerLocked) {
                markerAnnotation.setVisible(false);
                plot.setDomainCrosshairVisible(false);
                markerTitle.setVisible(false);
                markerTitle.setText("");
            }
        }

    });

    chartPanel.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            int clicks = e.getWheelRotation();
            plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() + clicks);
            plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + clicks);
        }
    });

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * /*from ww w  .  jav  a  2s .  c  o  m*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (xLowerBound != null && xUpperBound != null) {
        xAxis.setLowerBound(xLowerBound);
        xAxis.setUpperBound(xUpperBound);
    } else {
        xAxis.setAutoRange(true);
    }
    xAxis.setAxisLinePaint(Color.white);
    xAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (yLowerBound != null && yUpperBound != null) {
        yAxis.setLowerBound(yLowerBound);
        yAxis.setUpperBound(yUpperBound);
    } else
        yAxis.setAutoRange(true);

    yAxis.setAxisLinePaint(Color.white);
    yAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale paintScale = null;

    if (grayPaintScale) {
        paintScale = new GrayPaintScale(minScaleValue, maxScaleValue);
    } else {
        if (scaleLowerBound != null && scaleUpperBound != null) {
            paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray);
        } else {
            paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray);
        }
        for (int i = 0; i < zRangeArray.length; i++) {
            ZRange zRange = zRangeArray[i];
            ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor());

        }
    }

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setForegroundAlpha(0.66f);

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

    chart.removeLegend();

    NumberAxis scaleAxis = new NumberAxis(zLabel);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    if (scaleLowerBound != null && scaleUpperBound != null) {
        scaleAxis.setLowerBound(scaleLowerBound);
        scaleAxis.setUpperBound(scaleUpperBound);
    } else
        scaleAxis.setAutoRange(true);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        scaleAxis.setLabelFont(addLabelsStyle.getFont());
        scaleAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    if (blockHeight != null && blockWidth != null) {
        renderer.setBlockWidth(blockWidth.doubleValue());
        renderer.setBlockHeight(blockHeight.doubleValue());
    }

    PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.black));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(color);

    chart.addSubtitle(legend);

    //      chart.setBackgroundPaint(new Color(180, 180, 250));   
    chart.setBackgroundPaint(color);

    logger.debug("OUT");
    return chart;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java

/**
 * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
 * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
 * {@link DimensionConfig} s.//from   w w  w .  j av a 2s.  co  m
 */
private List<LegendTitle> createLegendTitles() {
    List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
    LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone()
            .getLegendConfiguration();

    LegendTitle legendTitle = new SmartLegendTitle(this,
            new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2),
            new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
    legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());

    RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
    if (position == null) {
        return legendTitles;
    }
    legendTitle.setPosition(position);

    if (legendConfiguration.isShowLegendFrame()) {
        legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
    }
    ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
    wrapper.add(legendTitle.getItemContainer());
    wrapper.setPadding(3, 3, 3, 3);
    legendTitle.setWrapper(wrapper);

    legendTitles.add(legendTitle);
    return legendTitles;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createXYAreaChart(String xAxisLabel, String yAxisLabel, XYDataset dataset,
        boolean includeLegend) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);/*w  w w. ja v  a2  s  . c o m*/
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    xyplot.setForegroundAlpha(0.8F);
    xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    DateAxis dateaxis = new DateAxis(xAxisLabel);
    dateaxis.setLowerMargin(0.0D);
    dateaxis.setUpperMargin(0.0D);
    xyplot.setDomainAxis(dateaxis);
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setRangeType(RangeType.POSITIVE);
    rangeAxis.setLabelFont(UIConstants.H5_FONT);
    rangeAxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));

    if (includeLegend) {
        LegendTitle legendtitle = new LegendTitle(xyplot);
        legendtitle.setItemFont(UIConstants.H5_FONT);
        legendtitle.setBackgroundPaint(UIConstants.INTEL_WHITE);
        legendtitle.setFrame(new BlockBorder(UIConstants.INTEL_BLUE));
        legendtitle.setPosition(RectangleEdge.BOTTOM);
        XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.97999999999999998D, 0.99999999999999998D,
                legendtitle, RectangleAnchor.TOP_RIGHT);
        // xytitleannotation.setMaxWidth(0.47999999999999998D);
        xyplot.addAnnotation(xytitleannotation);
    }

    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(1, UIConstants.INTEL_DARK_GRAY);
    xyitemrenderer.setSeriesPaint(0, NodeTypeViz.SWITCH.getColor());
    xyitemrenderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>",
                    Util.getHHMMSS(), new DecimalFormat("#,##0.00")));
    return jfreechart;
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

private void computeCoefficientOfDetermination() {
    int numberOfItems = scatterpointsDataset.getSeries(0).getItemCount();
    double arithmeticMeanOfX = 0; //arithmetic mean of X
    double arithmeticMeanOfY = 0; //arithmetic mean of Y
    double varX = 0; //variance of X
    double varY = 0; //variance of Y
    double coVarXY = 0; //covariance of X and Y;
    //compute arithmetic means
    for (int i = 0; i < numberOfItems; i++) {
        arithmeticMeanOfX += scatterpointsDataset.getXValue(0, i);
        arithmeticMeanOfY += scatterpointsDataset.getYValue(0, i);
    }/* www .  jav a  2 s  .  c o  m*/
    arithmeticMeanOfX /= numberOfItems;
    arithmeticMeanOfY /= numberOfItems;
    //compute variances and covariance
    for (int i = 0; i < numberOfItems; i++) {
        varX += Math.pow(scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX, 2);
        varY += Math.pow(scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY, 2);
        coVarXY += (scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX)
                * (scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY);
    }
    //computation of coefficient of determination
    double r2 = Math.pow(coVarXY, 2) / (varX * varY);
    r2 = MathUtils.round(r2, Math.pow(10.0, 5));

    final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
    final double intercept = coefficients[0];
    final double slope = coefficients[1];
    final String linearEquation;
    if (intercept >= 0) {
        linearEquation = "y = " + (float) slope + "x + " + (float) intercept;
    } else {
        linearEquation = "y = " + (float) slope + "x - " + Math.abs((float) intercept);
    }

    TextTitle tt = new TextTitle(linearEquation + "\nR = " + r2);
    tt.setTextAlignment(HorizontalAlignment.RIGHT);
    tt.setFont(chart.getLegend().getItemFont());
    tt.setBackgroundPaint(new Color(200, 200, 255, 100));
    tt.setFrame(new BlockBorder(Color.white));
    tt.setPosition(RectangleEdge.BOTTOM);

    r2Annotation = new XYTitleAnnotation(0.98, 0.02, tt, RectangleAnchor.BOTTOM_RIGHT);
    r2Annotation.setMaxWidth(0.48);
    getPlot().addAnnotation(r2Annotation);
}