jfreechart
jfreechart copied to clipboard
Gantt chart bars are drawn incorrectly when orientation of plot is vertical
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:
Vertical:
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
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);
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
It does indeed! Thank you very much, David! Especially for your fast response!!
Thanks for the feedback, I committed that fix for the next release.
Confirmed using latest JFreeChart 1.5.4-SNAPSHOT.