Is it possible with XYPlot to do same as in StackedBarChart?

A discussion forum for the JCommon class library.

Is it possible with XYPlot to do same as in StackedBarChart?

Postby rssx » Tue Dec 11, 2012 11:34 pm

I would very much like to show bar graphs in this style but at the same time I must be able to set the width of the each bar drawn for each dataset point
What I have done thus far now that I corrected my code to draw bars starting from
g2.fill3DRect((int) (bar.getX() -(barWidthAdjust/2)), (int) bar.getY(),(int) barWidthAdjust,(int) bar.getHeight(), true);
barWidthAdjust provides the means to tune the width of each bar to the fixed width I need it to be at.
within a painter object.

The painter object which is then assigned to the renderer which in turn is assigned to the XYPlot object . The trouble is it all looks very 2D and I want a snazzy 3D effect. How would I go about doing this?? Is it even possible?

Here is the code used now:
final JFreeChart chart = ChartFactory.createXYBarChart(
title,
legendX,
false,
legendY,
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
int seriesCt=dataset.getSeriesCount(); // V Should be the count of bars drawn assuming one series the dataset count would be from series#0
barWidthAdjust= (DEFAULT_CHART_WIDTH /(dataset.getItemCount(seriesCt-1)+1) -7);


GradientXYBarPainter painterG =new GradientXYBarPainter() { //0.40, 0.40, 0.20) {
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base, boolean pegShadow) {
System.out.println("wSHADDOW="+ bar.getWidth()+",H="+bar.getHeight());

}

@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
System.out.println("w="+ bar.getWidth()+",H="+bar.getHeight());

renderer.setShadowVisible(false);

g2.setColor(Color.red);
g2.fill3DRect((int) (bar.getX() -(barWidthAdjust/2)), (int) bar.getY(),(int) barWidthAdjust,(int) bar.getHeight(), true);
g2.draw3DRect((int) (bar.getX()-(barWidthAdjust/2)), (int) bar.getY(),(int) (barWidthAdjust),(int) bar.getHeight(),true);
}

};
xyrend.setBarPainter(painterG);
plot.setRenderer(xyrend);
rssx
 
Posts: 17
Joined: Wed Dec 05, 2012 6:49 am

Return to JCommon

Who is online

Users browsing this forum: No registered users and 2 guests