Change Bar Shape for a Gantt Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Change Bar Shape for a Gantt Chart

Post by hepzibahr » Fri Sep 16, 2011 12:59 pm

Code: Select all

 
Shape BARSHAPE = new Polygon(new int[] { 12, 8, -8, -8, 8 }, new int[] { 0, 4, 4, -4, -4 }, 5);//arrow
    GanttRenderer renderer = new GanttRenderer();
        CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}",
                DateFormat.getDateInstance());
        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 7));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseShape(BARSHAPE);
The shape is not getting reflected in the chart

Also i tried customizing the drawingSupplier and assigning to the plot as below

Code: Select all

 DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(new Paint[] { ChartColor.DARK_BLUE,
                ChartColor.DARK_CYAN, ChartColor.DARK_MAGENTA, ChartColor.DARK_RED, ChartColor.DARK_YELLOW,
                ChartColor.DARK_GRAY, ChartColor.GRAY, new Color(215, 0, 215), new Color(215, 64, 215), Color.pink },
                DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, new Shape[] { BARSHAPE });
categoryplot.setDrawingSupplier(drawingSupplier);
It does not get reflected in the chart
.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Change Bar Shape for a Gantt Chart

Post by paradoxoff » Sun Sep 18, 2011 2:16 pm

A BarRenderer just draws bars. The setting for the series shape is ignored.
You could extend BarRenderer and overridd the drawItem method. IN your new method, you could use most of the drawItem code from the superclass. The crucial thing will be not to directly draw the Rectangle bar that is calculated in lines 1060, but to use that to scale the shape returned from lookupSeriesShape(int, int). If that is not an instance of RectangularShape, you would also need to bypass the BarPainter.

Locked