for #1 you will have to extend the HighLowRenderer and implement the functionality you require.
Below is a quick example created by altering the "magic" numbers in the original renderer. You would have to look at other renderers (probably CandlestickRenderer) to figure out how to scale the width of the bars.
Code: Select all
public class MyHighLowRenderer extends HighLowRenderer{
public void drawItem(Graphics2D g2,
XYItemRendererState state,
Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState,
int pass) {
double x = dataset.getXValue(series, item);
if (!domainAxis.getRange().contains(x)) {
return; // the x value is not within the axis range
}
double xx = domainAxis.valueToJava2D(x, dataArea,
plot.getDomainAxisEdge());
// setup for collecting optional entity info...
Shape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge location = plot.getRangeAxisEdge();
Paint itemPaint = getItemPaint(series, item);
Stroke itemStroke = getItemStroke(series, item);
g2.setPaint(itemPaint);
g2.setStroke(itemStroke);
if (dataset instanceof OHLCDataset) {
OHLCDataset hld = (OHLCDataset) dataset;
double yHigh = hld.getHighValue(series, item);
double yLow = hld.getLowValue(series, item);
if (!Double.isNaN(yHigh) && !Double.isNaN(yLow)) {
double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea,
location);
double yyLow = rangeAxis.valueToJava2D(yLow, dataArea,
location);
if (orientation == PlotOrientation.HORIZONTAL) {
// g2.draw(new Line2D.Double(yyLow, xx, yyHigh, xx));
entityArea = new Rectangle2D.Double(Math.min(yyLow, yyHigh),
xx - 2.0, Math.abs(yyHigh - yyLow), 4.0);
g2.fill(entityArea);
}
else if (orientation == PlotOrientation.VERTICAL) {
// g2.draw(new Line2D.Double(xx, yyLow, xx, yyHigh));
entityArea = new Rectangle2D.Double(xx - 2.0,
Math.min(yyLow, yyHigh), 4.0,
Math.abs(yyHigh - yyLow));
g2.fill(entityArea);
}
}
double delta = 8.0;
if (domainAxis.isInverted()) {
delta = -delta;
}
if (getDrawOpenTicks()) {
double yOpen = hld.getOpenValue(series, item);
if (!Double.isNaN(yOpen)) {
double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea,
location);
if (getOpenTickPaint() != null) {
g2.setPaint(getOpenTickPaint());
}
else {
g2.setPaint(itemPaint);
}
if (orientation == PlotOrientation.HORIZONTAL) {
g2.draw(new Line2D.Double(yyOpen, xx + delta, yyOpen,
xx));
}
else if (orientation == PlotOrientation.VERTICAL) {
g2.draw(new Line2D.Double(xx - delta, yyOpen, xx,
yyOpen));
}
}
}
if (getDrawCloseTicks()) {
double yClose = hld.getCloseValue(series, item);
if (!Double.isNaN(yClose)) {
double yyClose = rangeAxis.valueToJava2D(
yClose, dataArea, location);
if (getCloseTickPaint() != null) {
g2.setPaint(getCloseTickPaint());
}
else {
g2.setPaint(itemPaint);
}
if (orientation == PlotOrientation.HORIZONTAL) {
g2.draw(new Line2D.Double(yyClose, xx, yyClose,
xx - delta));
}
else if (orientation == PlotOrientation.VERTICAL) {
g2.draw(new Line2D.Double(xx, yyClose, xx + delta,
yyClose));
}
}
}
}
else {
// not a HighLowDataset, so just draw a line connecting this point
// with the previous point...
if (item > 0) {
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
double y = dataset.getYValue(series, item);
if (Double.isNaN(x0) || Double.isNaN(y0) || Double.isNaN(y)) {
return;
}
double xx0 = domainAxis.valueToJava2D(x0, dataArea,
plot.getDomainAxisEdge());
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
double yy = rangeAxis.valueToJava2D(y, dataArea, location);
if (orientation == PlotOrientation.HORIZONTAL) {
g2.draw(new Line2D.Double(yy0, xx0, yy, xx));
}
else if (orientation == PlotOrientation.VERTICAL) {
g2.draw(new Line2D.Double(xx0, yy0, xx, yy));
}
}
}
// add an entity for the item...
if (entities != null) {
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(entityArea, dataset,
series, item, tip, url);
entities.add(entity);
}
}
}