JFreeChart蜘蛛网图添加刻度解决方案
时间:2010-12-16 王杰瑞
JFreeChart是老牌Java开源图表工具包,也是JFreeReport的重要组成部分, 在业界被广泛应用。当然,这个工具包依然有很多美中不足,确切的说,有很多 具体的应用还需要我们拓展,比如蜘蛛网图(Spider Web)的刻度问题。
这是使用原来SpiderWebPlot时解决前的图示:
下面是使用MySpiderWebPlot解决后的图示:
JFreeChart岌幃利夕耶紗震業盾畳圭宛(2)
扮寂:2010-12-16 藍旬誹
MySpiderWebPlot旗鷹泌和?
public class MySpiderWebPlot extends SpiderWebPlot {
private int ticks = DEFAULT_TICKS;
private static final int DEFAULT_TICKS = 5;
private NumberFormat format = NumberFormat.getInstance ();
private static final double PERPENDICULAR = 90;
private static final double TICK_SCALE = 0.015;
private int valueLabelGap = DEFAULT_GAP;
private static final int DEFAULT_GAP = 10;
private static final double THRESHOLD = 15;
MySpiderWebPlot(CategoryDataset createCategoryDataset) {
super(createCategoryDataset);
}
@Override
protected void drawLabel(final Graphics2D g2, final Rectangle2D plotArea, final double value,
final int cat, final double startAngle, final double extent) {
super.drawLabel(g2, plotArea, value, cat, startAngle, extent);
final FontRenderContext frc = g2.getFontRenderContext();
final double[] transformed = new double[2];
final double[] transformer = new double[2];
final Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
for (int i = 1; i <= ticks; i++) {
final Point2D point1 = arc1.getEndPoint ();
final double deltaX = plotArea.getCenterX ();
final double deltaY = plotArea.getCenterY ();
double labelX = point1.getX() - deltaX;
double labelY = point1.getY() - deltaY;
final double scale = ((double) i / (double) ticks);
final AffineTransform tx = AffineTransform.getScaleInstance(scale, scale);
final AffineTransform pointTrans = AffineTransform.getScaleInstance(scale + TICK_SCALE, scale + TICK_SCALE);
transformer[0] = labelX;
transformer[1] = labelY;
pointTrans.transform(transformer, 0, transformed, 0, 1);
final double pointX = transformed[0] + deltaX;
final double pointY = transformed[1] + deltaY;
tx.transform(transformer, 0, transformed, 0, 1);
labelX = transformed[0] + deltaX;
labelY = transformed[1] + deltaY;
double rotated = (PERPENDICULAR);
AffineTransform rotateTrans = AffineTransf
|