问题
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