我正在使用Jfreechart绘制x-y轴我想在此x-y轴上绘制一个矩形和一个圆。你知道怎么可能吗?是否有更好的方法(而不是jfreechart)在其上绘制x-y轴及其形状?
答案 0 :(得分:0)
我使用注释功能将圆形或其他项目绘制到XY图表图表上。要添加圆圈,请使用" addAnnotation(XYShapeAnnotation(new Ellipse2D.Double(...)))"例如。这是一个示例方法:
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;
}
}