How to generate a bar chart in JFreeChart with default components' size?

怎甘沉沦 提交于 2019-12-12 01:32:46

问题


I am trying to generate one bar chart but it's forcing me to control width and height by calculating size of labels from domain axis and causing problems when they are too large (the start of the columns' values get in the middle of the chart).

Do you have any suggestion ?

Thank you.


回答1:


You can change the renderer on the chart by creating a custom painter that repaints the graphics; the Painter code doesn't seem to display correctly here. I used a widthMultiplier to control the size of my bars:

GradientXYBarPainter xyBarpainter = new GradientXYBarPainter() {

    @Override
    public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
            int column, RectangularShape bar, RectangleEdge base) {
        Rectangle2D rect = bar.getFrame();
        rect.setRect(rect.getX(), rect.getY(),
            rect.getWidth() * widthMultiplier, rect.getHeight());
        bar.setFrame(rect);
        super.paintBar(g2, renderer, row, column, bar, base);
    }
};
StackedXYBarRenderer rend = new StackedXYBarRenderer();
rend.setBarPainter(xyBarpainter);


来源:https://stackoverflow.com/questions/3406578/how-to-generate-a-bar-chart-in-jfreechart-with-default-components-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!