Decreasing gap for horizontal bar chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sayan_maity
Posts: 15
Joined: Tue Feb 13, 2007 9:29 am

Decreasing gap for horizontal bar chart

Post by sayan_maity » Wed Mar 07, 2007 5:22 am

Hi,
I want to decrease the gap on the left hand side of the horizontal bar chart i.e. the gap between the outline and the label. I am using category axis.

Thanks,
Sayan

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Mar 07, 2007 11:02 am

You ought to be able to do this:

Code: Select all

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setInsets(new RectangleInsets(0, 0, 0, 0));
        plot.getDomainAxis().setLabelInsets(new RectangleInsets(0, 0, 0, 0));
While I was checking this, I spotted a bug which will be fixed by this patch (for inclusion in the 1.0.5 release):

Code: Select all

### Eclipse Workspace Patch 1.0
#P jfreechart-1.0.x-cvs
Index: source/org/jfree/chart/axis/CategoryAxis.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/axis/CategoryAxis.java,v
retrieving revision 1.18.2.11
diff -u -r1.18.2.11 CategoryAxis.java
--- source/org/jfree/chart/axis/CategoryAxis.java	7 Mar 2007 09:39:14 -0000	1.18.2.11
+++ source/org/jfree/chart/axis/CategoryAxis.java	7 Mar 2007 10:02:05 -0000
@@ -82,7 +82,7 @@
  * 02-Oct-2006 : Updated category label entity (DG);
  * 30-Oct-2006 : Updated refreshTicks() method to account for possibility of
  *               multiple domain axes (DG);
- * 07-Mar-2007 : Updated API docs (DG);
+ * 07-Mar-2007 : Fixed bug in axis label positioning (DG);
  *
  */
 
@@ -958,19 +958,19 @@
             }
 
             if (edge.equals(RectangleEdge.TOP)) {
-                double h = state.getMax();
+                double h = state.getMax() + this.categoryLabelPositionOffset;
                 state.cursorUp(h);
             }
             else if (edge.equals(RectangleEdge.BOTTOM)) {
-                double h = state.getMax();
+                double h = state.getMax() + this.categoryLabelPositionOffset;
                 state.cursorDown(h);
             }
             else if (edge == RectangleEdge.LEFT) {
-                double w = state.getMax();
+                double w = state.getMax() + this.categoryLabelPositionOffset;
                 state.cursorLeft(w);
             }
             else if (edge == RectangleEdge.RIGHT) {
-                double w = state.getMax();
+                double w = state.getMax() + this.categoryLabelPositionOffset;
                 state.cursorRight(w);
             }
         }
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked