JFREE Barchart add space between title and chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anonymousx
Posts: 2
Joined: Tue Jul 01, 2014 8:11 pm
antibot: No, of course not.

JFREE Barchart add space between title and chart

Post by anonymousx » Thu Jul 03, 2014 3:31 pm

Hello. I just recently made a barchart. The only issue I am having is there is not enough space between the graph and the title on top. I would like the title, with some added spacing underneath, and then the graph. Rather, the title falls right on top of the top gridline where the chart starts. A snippet of the code that deals with the rendering of the graph is here.

Code: Select all

public JFreeChart createChart(final CategoryDataset categorydataset) {
                final JFreeChart chart = ChartFactory.createBarChart(
                        "Title",         
                        "",               
                        "",                  
                        categorydataset,                  
                        PlotOrientation.VERTICAL, 
                        false,                     
                        true,                     
                        false                     
                    );
                        chart.setBackgroundPaint(Color.white);


                final CategoryPlot plot = chart.getCategoryPlot();
                        plot.setBackgroundPaint(Color.white);
                        plot.setDomainGridlinePaint(Color.black);
                        plot.setRangeGridlinePaint(Color.black);
                        plot.setDomainGridlineStroke(new BasicStroke(0.5f));
                        plot.setRangeGridlineStroke(new BasicStroke(0.5f));
                        BarRenderer br = (BarRenderer) plot.getRenderer();
                        br.setMaximumBarWidth(.095);

  
                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setTickLabelFont(new Font("Helvetica", Font.BOLD, 14));
                        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                        rangeAxis.setAutoRangeStickyZero(false);
                rangeAxis.setUpperMargin(0.21);


                final BarRenderer renderer = (BarRenderer) plot.getRenderer();
                        renderer.setDrawBarOutline(false);
                        renderer.setBarPainter(new StandardBarPainter());
                        renderer.setItemMargin(0.0);
                        

                final GradientPaint gp0 = new GradientPaint(
                        0.0f, 0.0f, new Color(79, 129, 189), 
                        0.0f, 0.0f, new Color(79, 129, 189)
                        
                    );
                renderer.setSeriesPaint(0, gp0);

                final CategoryAxis domainAxis = plot.getDomainAxis();
                domainAxis.setTickLabelFont(new Font("Helvetica", Font.BOLD, 14));
                        domainAxis.setCategoryLabelPositions(STANDARD
                    );
                        
        return chart;
        }
How or where would I edit this code in order to add spacing between the above title "title" and the chart? I thank everyone for your time in reading and at least considering my question, even if an answer will not be the result. Have a good day.

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

Re: JFREE Barchart add space between title and chart

Post by david.gilbert » Thu Jul 03, 2014 3:39 pm

One way is:

Code: Select all

        chart.getTitle().setPadding(2, 2, 20, 2);
David Gilbert
JFreeChart Project Leader

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

Locked