开发者

drawing shapes in jfreechart

开发者 https://www.devze.com 2023-03-18 18:11 出处:网络
I am using Jf开发者_开发问答reechart to draw x-y axis I want to draw a rectangle and a circle on this x-y axis. Do you know how is it possible? Is there any better way(rather than jfreechart) to draw

I am using Jf开发者_开发问答reechart to draw x-y axis I want to draw a rectangle and a circle on this x-y axis. Do you know how is it possible? Is there any better way(rather than jfreechart) to draw x-y axis and its shapes on it?


I draw circles or other items onto an XY chart chart with the annotations capability. To add a circle use "addAnnotation(XYShapeAnnotation(new Ellipse2D.Double(...)))" for example. Here's an example method:

public void markChartAt2( float fromX, float fromY, float toX, float toY, markType markerTyp, Color lineColor, String toolTip ) {
    XYLineAnnotation lineAnnotation;
    XYShapeAnnotation shapeAnnotation;
    if (lineColor == null)
        lineColor = Color.black;
    maxY = yAxis.getUpperBound();
    minY = yAxis.getLowerBound();
    yFactor = (maxY - minY) * .005d;
    maxX = xAxis.getUpperBound();
    minX = xAxis.getLowerBound();
    xFactor = (maxX - minX) * .0005d;       
    switch ( markerTyp ){
    case CIRCLE:
        shapeAnnotation = new XYShapeAnnotation(
                new Ellipse2D.Double( fromX - xFactor, fromY - yFactor, xFactor+xFactor, yFactor+yFactor ),
                markerLineWidth, lineColor ) ;
        shapeAnnotation.setToolTipText( toolTip );
        priceXYPlot.addAnnotation(shapeAnnotation);
        break;
    case SQUARE:
        shapeAnnotation = new XYShapeAnnotation(
                new Rectangle2D.Double( fromX - xFactor, fromY - yFactor, xFactor+xFactor, yFactor+yFactor ),
                markerLineWidth, lineColor );
        shapeAnnotation.setToolTipText( toolTip );
        priceXYPlot.addAnnotation( shapeAnnotation );
        break;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消