画一个三角形的形状

时间:2015-01-22 15:19:36

标签: java graphics paint jfreechart

我正在尝试在JFreeChart中的GanttRenderer类中绘制三角形。我可以从Shape Utilities获得形状:

Shape triangle = ShapeUtilities.createDownTriangle(4.0f);

如何在正确的位置绘制形状并设置尺寸参数?

public class Renderer extends GanttRenderer {

private final TaskSeriesCollection model;

public Renderer(TaskSeriesCollection model) {
    this.model = model;
}
@Override
protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {   

        /*Some other code here*/

            Shape triangle = ShapeUtilities.createDownTriangle(4.0f);
//              Rectangle2D triangleContainer = triangle.getBounds2D();
//              triangleContainer.setRect(subtaskStartTranslated, rectYAxisStart, rectBreadth, rectBreadth);

            g2.setPaint(new Color(255,0,0));
            g2.draw(triangle);

        /*Some other code here*/
    }
}

1 个答案:

答案 0 :(得分:0)

创建原始形状的平移形状,如下所示:

Shape downTriangle = ShapeUtils.createTranslatedShape(ShapeUtils.createDownTriangle(sizeFactor), sizeFactor, sizeFactor);