jfreechart icon indicating copy to clipboard operation
jfreechart copied to clipboard

Gantt chart bars are drawn incorrectly when orientation of plot is vertical

Open danno-1 opened this issue 3 years ago • 5 comments

Using this example (or any other for that matter) https://www.boraji.com/jfreechart-gantt-chart-example

add this line after the JFreeChart chart = ChartFactory.createGanttChart call

chart.getPlot().setOrientation(PlotOrientation.VERTICAL)

You'll see that the first two bars (Requirement bars) are the same size and touching the axis, rather than the Actual bar being smaller than the Estimated bar, and the third bar (Design Actual) is very wrong, touching the axis and shorter than it should be. And others are wrong as well.

Horizontal: Horizontal Gantt Chart

Vertical: Vertical Gantt Chart

This is a problem in both 1.0 and 1.5 versions of JFree. Hoping someone can point me to a fix in the renderer I can do myself before the fix is in an offical JFree release.

Thanks! Dan

danno-1 avatar Jul 20 '21 12:07 danno-1

I see the same effect with v1.5.3. For reference,

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
…
CategoryPlot plot = (CategoryPlot)chart.getPlot();
plot.setOrientation(PlotOrientation.VERTICAL);

trashgod avatar Jul 20 '21 17:07 trashgod

Does this fix it for you?

Index: src/main/java/org/jfree/chart/renderer/category/GanttRenderer.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8

diff --git a/src/main/java/org/jfree/chart/renderer/category/GanttRenderer.java b/src/main/java/org/jfree/chart/renderer/category/GanttRenderer.java --- a/src/main/java/org/jfree/chart/renderer/category/GanttRenderer.java (date 1626807961092) +++ b/src/main/java/org/jfree/chart/renderer/category/GanttRenderer.java (date 1626807961092) @@ -446,7 +446,7 @@ barBase = RectangleEdge.LEFT; } else if (orientation == PlotOrientation.VERTICAL) {

  •        bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth,
    
  •        bar = new Rectangle2D.Double(rectStart, java2dValue0, rectBreadth,
                   rectLength);
           barBase = RectangleEdge.BOTTOM;
       }
    

Best regards, David

jfree avatar Jul 20 '21 19:07 jfree

It does indeed! Thank you very much, David! Especially for your fast response!!

Updated Gantt Chart

danno-1 avatar Jul 20 '21 19:07 danno-1

Thanks for the feedback, I committed that fix for the next release.

jfree avatar Jul 20 '21 20:07 jfree

Confirmed using latest JFreeChart 1.5.4-SNAPSHOT.

trashgod avatar Jul 21 '21 00:07 trashgod