Example usage for org.jfree.chart.renderer.xy DefaultXYItemRenderer setPaint

List of usage examples for org.jfree.chart.renderer.xy DefaultXYItemRenderer setPaint

Introduction

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

Prototype

public void setPaint(Paint paint) 

Source Link

Document

Sets the paint to be used for ALL series, and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java

/**
 * method to create a working plot (to contain our data)
 * // w  w  w .  j av a2 s.  c om
 * @return the chart, in it's own panel
 */
@SuppressWarnings("deprecation")
protected void createStackedPlot() {

    // first create the x (time) axis
    final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss");
    _df.setTimeZone(TimeZone.getTimeZone("GMT"));

    final DateAxis xAxis = new CachedTickDateAxis("");
    xAxis.setDateFormatOverride(_df);
    Font tickLabelFont = new Font("Courier", Font.PLAIN, 13);
    xAxis.setTickLabelFont(tickLabelFont);
    xAxis.setTickLabelPaint(Color.BLACK);

    xAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits());
    xAxis.setAutoTickUnitSelection(true);

    // create the special stepper plot
    _dotPlot = new XYPlot();
    NumberAxis errorAxis = new NumberAxis("Error (" + getUnits() + ")");
    Font axisLabelFont = new Font("Courier", Font.PLAIN, 16);
    errorAxis.setLabelFont(axisLabelFont);
    errorAxis.setTickLabelFont(tickLabelFont);
    _dotPlot.setRangeAxis(errorAxis);
    _dotPlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    _dotPlot.setRenderer(new ColourStandardXYItemRenderer(null, null, _dotPlot));

    _dotPlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    _dotPlot.setRangeGridlineStroke(new BasicStroke(2));
    _dotPlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    _dotPlot.setDomainGridlineStroke(new BasicStroke(2));

    // now try to do add a zero marker on the error bar
    final Paint thePaint = Color.DARK_GRAY;
    final Stroke theStroke = new BasicStroke(3);
    final ValueMarker zeroMarker = new ValueMarker(0.0, thePaint, theStroke);
    _dotPlot.addRangeMarker(zeroMarker);

    _linePlot = new XYPlot();
    final NumberAxis absBrgAxis = new NumberAxis("Absolute (" + getUnits() + ")");
    absBrgAxis.setLabelFont(axisLabelFont);
    absBrgAxis.setTickLabelFont(tickLabelFont);
    _linePlot.setRangeAxis(absBrgAxis);
    absBrgAxis.setAutoRangeIncludesZero(false);
    _linePlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    final DefaultXYItemRenderer lineRend = new ColourStandardXYItemRenderer(null, null, _linePlot);
    lineRend.setPaint(Color.DARK_GRAY);
    _linePlot.setRenderer(lineRend);

    _linePlot.setDomainCrosshairVisible(true);
    _linePlot.setRangeCrosshairVisible(true);
    _linePlot.setDomainCrosshairPaint(Color.GRAY);
    _linePlot.setRangeCrosshairPaint(Color.GRAY);
    _linePlot.setDomainCrosshairStroke(new BasicStroke(3.0f));
    _linePlot.setRangeCrosshairStroke(new BasicStroke(3.0f));

    _linePlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    _linePlot.setRangeGridlineStroke(new BasicStroke(2));
    _linePlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    _linePlot.setDomainGridlineStroke(new BasicStroke(2));

    // and the plot object to display the cross hair value
    final XYTextAnnotation annot = new XYTextAnnotation("-----", 2, 2);
    annot.setTextAnchor(TextAnchor.TOP_LEFT);

    Font annotationFont = new Font("Courier", Font.BOLD, 16);
    annot.setFont(annotationFont);
    annot.setPaint(Color.DARK_GRAY);
    annot.setBackgroundPaint(Color.white);
    _linePlot.addAnnotation(annot);

    // give them a high contrast backdrop
    _dotPlot.setBackgroundPaint(Color.white);
    _linePlot.setBackgroundPaint(Color.white);

    // set the y axes to autocalculate
    _dotPlot.getRangeAxis().setAutoRange(true);
    _linePlot.getRangeAxis().setAutoRange(true);

    _combined = new CombinedDomainXYPlot(xAxis);

    _combined.add(_linePlot);
    _combined.add(_dotPlot);

    _combined.setOrientation(PlotOrientation.HORIZONTAL);

    // put the plot into a chart
    _myChart = new JFreeChart(null, null, _combined, true);

    final LegendItemSource[] sources = { _linePlot };
    _myChart.getLegend().setSources(sources);

    _myChart.addProgressListener(new ChartProgressListener() {
        public void chartProgress(final ChartProgressEvent cpe) {
            if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED)
                return;

            // is hte line plot visible?
            if (!_showLinePlot.isChecked())
                return;

            // double-check our label is still in the right place
            final double xVal = _linePlot.getRangeAxis().getLowerBound();
            final double yVal = _linePlot.getDomainAxis().getUpperBound();
            boolean annotChanged = false;
            if (annot.getX() != yVal) {
                annot.setX(yVal);
                annotChanged = true;
            }
            if (annot.getY() != xVal) {
                annot.setY(xVal);
                annotChanged = true;
            }
            // and write the text
            final String numA = MWC.Utilities.TextFormatting.GeneralFormat
                    .formatOneDecimalPlace(_linePlot.getRangeCrosshairValue());
            final Date newDate = new Date((long) _linePlot.getDomainCrosshairValue());
            final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss");
            _df.setTimeZone(TimeZone.getTimeZone("GMT"));
            final String dateVal = _df.format(newDate);
            final String theMessage = " [" + dateVal + "," + numA + "]";
            if (!theMessage.equals(annot.getText())) {
                annot.setText(theMessage);
                annotChanged = true;
            }
            if (annotChanged) {
                _linePlot.removeAnnotation(annot);
                _linePlot.addAnnotation(annot);
            }
        }
    });

    // and insert into the panel
    _holder.setChart(_myChart);

    // do a little tidying to reflect the memento settings
    if (!_showLinePlot.isChecked())
        _combined.remove(_linePlot);
    if (!_showDotPlot.isChecked() && _showLinePlot.isChecked())
        _combined.remove(_dotPlot);
}