afreechart/src/main/java/org/afree/chart/AFreeChart.java
/**
     * Draws the chart on a graphics device (such as the screen or a
     * printer).
     * <P>
     * This method is the focus of the entire AFreeChart library.
     * 
     * @param canvas
     *            the graphics device.
     * @param chartArea
     *            the area within which the chart should be drawn.
     * @param anchor
     *            the anchor point (in Java2D space) for the chart (
     *            <code>null</code> permitted).
     * @param info
     *            records info about the drawing (null means collect no info).
     */
Draws the chart on a graphics device (such as the screen or a
printer).

This method is the focus of the entire AFreeChart library.

@param canvas
the graphics device.
@param chartArea
the area within which the chart should be drawn.
@param anchor
the anchor point (in Java2D space) for the chart (
null permitted).
@param info
records info about the drawing (null means collect no info).
Draws the chart on a graphics device ( such as the screen or a printer ) . This method is the focus of the entire AFreeChart library . @param canvas the graphics device . @param chartArea the area within which the chart should be drawn . @param anchor the anchor point ( in Java2D space ) for the chart ( null permitted ) . @param info records info about the drawing ( null means collect no info ) .
public void draw(Canvas canvas, RectShape chartArea, PointF anchor,
            ChartRenderingInfo info) {
        EntityCollection entities = null;
        notifyListeners(new ChartProgressEvent(this, this,
                ChartProgressEvent.DRAWING_STARTED, 0));
        if (info != null) {
            info.clear();
            info.setChartArea(chartArea);
            entities = info.getEntityCollection();
        }
        if (entities != null) {
            entities.add(new AFreeChartEntity((RectShape) chartArea.clone(), this));
        }
        Rect savedClip = canvas.getClipBounds();
        canvas.clipRect((float) chartArea.getMinX(), (float) chartArea.getMinY(),
                (float) chartArea.getMaxX() , (float) chartArea.getMaxY());
        if (this.backgroundPaintType != null) {
            Paint paint = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, this.backgroundPaintType);
            chartArea.fill(canvas, paint);
        }
        if (isBorderVisible()) {
            PaintType paintType = getBorderPaintType();
            if (paintType != null) {
                RectShape borderArea = new RectShape(chartArea
                        .getX(), chartArea.getY(), chartArea.getWidth() - 1.0,
                        chartArea.getHeight() - 1.0);
                Paint paint = PaintUtility.createPaint(borderPaintType, borderStroke, borderEffect);
                borderArea.draw(canvas, paint);
            }
        }
        RectShape nonTitleArea = new RectShape();
        nonTitleArea.setRect(chartArea);
        if (this.padding != null)
            this.padding.trim(nonTitleArea);
        if (this.title != null) {
            EntityCollection e = drawTitle(this.title, canvas, nonTitleArea,
                    (entities != null));
            if (e != null) {
                entities.addAll(e);
            }
        }
        Iterator iterator = this.subtitles.iterator();
        while (iterator.hasNext()) {
            Title currentTitle = (Title) iterator.next();
            if (currentTitle.isVisible()) {
                EntityCollection e = drawTitle(currentTitle, canvas, nonTitleArea,
                        (entities != null));
                if (e != null) {
                    entities.addAll(e);
                }
            }
        }
        RectShape plotArea = nonTitleArea;
        PlotRenderingInfo plotInfo = null;
        if (info != null) {
            plotInfo = info.getPlotInfo();
        }
        this.plot.draw(canvas, plotArea, anchor, null, plotInfo);
        canvas.clipRect(savedClip, Op.REPLACE);
        notifyListeners(new ChartProgressEvent(this, this,
                ChartProgressEvent.DRAWING_FINISHED, 100));
    }
public void draw ( Canvas canvas , RectShape chartArea , PointF anchor , ChartRenderingInfo info ) { EntityCollection entities = null ; notifyListeners ( new ChartProgressEvent ( this , this , ChartProgressEvent . DRAWING_STARTED , 0 ) ) ; if ( info != null ) { info . clear ( ) ; info . setChartArea ( chartArea ) ; entities = info . getEntityCollection ( ) ; } if ( entities != null ) { entities . add ( new AFreeChartEntity ( ( RectShape ) chartArea . clone ( ) , this ) ) ; } Rect savedClip = canvas . getClipBounds ( ) ; canvas . clipRect ( ( float ) chartArea . getMinX ( ) , ( float ) chartArea . getMinY ( ) , ( float ) chartArea . getMaxX ( ) , ( float ) chartArea . getMaxY ( ) ) ; if ( this . backgroundPaintType != null ) { Paint paint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , this . backgroundPaintType ) ; chartArea . fill ( canvas , paint ) ; } if ( isBorderVisible ( ) ) { PaintType paintType = getBorderPaintType ( ) ; if ( paintType != null ) { RectShape borderArea = new RectShape ( chartArea . getX ( ) , chartArea . getY ( ) , chartArea . getWidth ( ) - 1.0 , chartArea . getHeight ( ) - 1.0 ) ; Paint paint = PaintUtility . createPaint ( borderPaintType , borderStroke , borderEffect ) ; borderArea . draw ( canvas , paint ) ; } } RectShape nonTitleArea = new RectShape ( ) ; nonTitleArea . setRect ( chartArea ) ; if ( this . padding != null ) this . padding . trim ( nonTitleArea ) ; if ( this . title != null ) { EntityCollection e = drawTitle ( this . title , canvas , nonTitleArea , ( entities != null ) ) ; if ( e != null ) { entities . addAll ( e ) ; } } Iterator iterator = this . subtitles . iterator ( ) ; while ( iterator . hasNext ( ) ) { Title currentTitle = ( Title ) iterator . next ( ) ; if ( currentTitle . isVisible ( ) ) { EntityCollection e = drawTitle ( currentTitle , canvas , nonTitleArea , ( entities != null ) ) ; if ( e != null ) { entities . addAll ( e ) ; } } } RectShape plotArea = nonTitleArea ; PlotRenderingInfo plotInfo = null ; if ( info != null ) { plotInfo = info . getPlotInfo ( ) ; } this . plot . draw ( canvas , plotArea , anchor , null , plotInfo ) ; canvas . clipRect ( savedClip , Op . REPLACE ) ; notifyListeners ( new ChartProgressEvent ( this , this , ChartProgressEvent . DRAWING_FINISHED , 100 ) ) ; }
Draws the chart on a graphics device (such as the screen or a
 printer).
Draws the chart on a graphics device ( such as the screen or a printer ) .
// record the chart area, if info is requested... // ensure no drawing occurs outside chart area... // draw the chart background... // draw the title and subtitles... // draw the plot (axes and data visualisation)