Hi,
I am using an XYPlot to plot a Time vs Price chart. I am dynamically calculating the candlestick width for this candlestick chart as shown below.
public XYItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
XYPlot plot,
XYDataset dataset,
PlotRenderingInfo info)
{
1. IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
2. ValueAxis domainAxis = plot.getDomainAxis();
3. double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(0, 0), dataArea, plot.getDomainAxisEdge());
4. double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(0, 0), dataArea, plot.getDomainAxisEdge());
5. this.stickWidth = Math.ceil(Math.abs(endPos - startPos)); //Calculate the stick with once.
return new XYItemRendererState(info);
}
double value1 = intervalXYData.getStartXValue(0, 0);
double value2 = intervalXYData.getEndXValue(0, 0);
The difference between these 2 values is always going to be 240000 milli seconds (value1 = x; value2 = x + 240000). However, this method call returns the same 2D value in both the cases. The problem is that the candlestick width is turning out to be zero (startPos and endPos are same in line 3 and 4). Hence, the renderer draws a vertical line in place of a candlestick. Please help me resolve this issue.
Thanks.