AffineTransform yaxis1 = getTransform(CoordSystem.FIRST_YAXIS);
AffineTransform yaxis2 = getTransform(CoordSystem.SECOND_YAXIS);
int datasetcount = m.getDataSetNumber();
Point2D point1 = yaxis1.transform(new Point2D.Float((float)con.getMinimumColumnValue(),
con.getMaximumValue().floatValue()),
null);
Point2D point2 = yaxis1.transform(new Point2D.Float((float)con.getMaximumColumnValue(),
con.getMaximumValue().floatValue()),
null);
Point2D value = point1;
int dataunitwidth = (int)((point2.getX() - point1.getX()) / con.getMaximumColumnValue());
int boxwidth = (int)(dataunitwidth * boxWidth / datasetcount);
float margin = (float)(dataunitwidth * ((1.0 - boxWidth)/2f));
Point2D pointzero;
if(con.getMinimumValue().floatValue() > 0)
pointzero = yaxis1.transform(new Point2D.Float((float)con.getMinimumColumnValue(),
con.getMinimumValue().floatValue()),
null);
else if(con.getMaximumValue().floatValue() < 0)
pointzero = yaxis1.transform(new Point2D.Float((float)con.getMinimumColumnValue(),
con.getMaximumValue().floatValue()),
null);
else
pointzero = yaxis1.transform(new Point2D.Float((float)con.getMinimumColumnValue(),
0f),
null);
FontRenderContext columnTopfrc = null;
LineMetrics lm = null;
DecimalFormat df = null;
Rectangle2D fontRec = null;
String columnTop = null;
if (barTopFormat != null) {
g.setFont(barTopFont);
columnTopfrc = new FontRenderContext(null, false, false);
}
/* We paint the values starting at x-value "0".
* As we only render BarCharts for ChartDataModels with
* non-numeric x-axis values we don't have to read those
* values from the data model. You can look in
* ObjectChartDataModel to see, how the x-axis bounds
* are defined: the minimum value is always 0, the maximum
* value is the amount of non-numeric x-axis values.
*/
for(int i = 0; i < datasetcount; i++) {
//System.out.println("** DataSet "+i);
for(int j = 0; j < m.getDataSetLength(i); j++) {
yaxis1.transform(new Point2D.Float((float)j, m.getValueAt(i, j).floatValue()),
value);
Rectangle2D box =
new Rectangle2D.Float((float)(value.getX() + margin + i*boxwidth),
(float)Math.min(value.getY(), pointzero.getY()),
(float)boxwidth,
(float)Math.abs(pointzero.getY() - value.getY()));
g.setColor(rcm.getColor(i));
g.fill(box);
g.setColor(Color.black);
g.draw(box);
if (barTopFormat != null) {
//get value for zero'th set, index j
columnTop = barTopFormat.format(model.getValueAt(i,j).doubleValue());
fontRec = barTopFont.getStringBounds(columnTop, columnTopfrc);
lm = barTopFont.getLineMetrics(columnTop, columnTopfrc);
g.drawString(columnTop,
(float)(value.getX() + i*boxwidth +
(boxwidth - fontRec.getWidth())/2) - lm.getLeading(),
(float)(Math.min(value.getY(), pointzero.getY())-lm.getDescent()));
}
}
}
}//end render method