Width of the bar in Jfreechart

前端 未结 4 1819
眼角桃花
眼角桃花 2020-12-09 09:56

Is there a way to adjust the width of the bars in a Barchart?

I create my chart with the following code.

final JFreeChart chart = ChartFactory.create         


        
4条回答
  •  青春惊慌失措
    2020-12-09 10:38

    You can't directly specify the width of the bars, but there's a few attributes that can be changed which affect the width. You should take a look at the lowerMargin, upperMargin and categoryMargin attributes defined by the CategoryAxis or the itemMargin attribute in the BarRenderer.

    For example:

        BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
        renderer.setItemMargin(.1);
    

    The double specified in setItemMargin(double percent) is the percentage of the overall length of the category axis that will be used for the space between the bars within the same category (default is .2 or 20%). The smaller this value is, the larger the bars will be.

提交回复
热议问题