Hi,
I think this bug is still present in 1.0.17, here's a code sample:
Code: Select all
package com.timestored.sqldash.chart;
import java.util.Date;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.DateTickUnitType;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.SegmentedTimeline;
import org.jfree.chart.labels.HighLowItemLabelGenerator;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.CandlestickRenderer;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
public class CombinedXYPlotDemo1 extends ApplicationFrame {
public CombinedXYPlotDemo1(final String title) {
super(title);
final JFreeChart chart = createCombinedChart();
final ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
setContentPane(panel);
}
private JFreeChart createCombinedChart() {
int n = 100;
final XYDataset data1 = new DefaultHighLowDataset("Series 1", getDTS(n), arr(n, 5), arr(n, 2),
arr(n, 3), arr(n, 4), arr(n, 100));
// create dataset 2...
TimeSeriesCollection dataset2 = new TimeSeriesCollection();
TimeSeries tSeries = new TimeSeries("tlabel");
for(int i=0; i<n; i++) {
tSeries.addOrUpdate(new Day(new Date(90,1,i)), n+0.1);
}
dataset2.addSeries(tSeries);
DateAxis timeAxis = new DateAxis("Date");
// comment out the line below and no infinite loop occurs.
timeAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
// or add these lines
// timeAxis.setAutoTickUnitSelection(false);
// timeAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1));
CandlestickRenderer candle = new CandlestickRenderer(4,false,new HighLowItemLabelGenerator());
XYBarRenderer rr2 = new XYBarRenderer();
XYPlot subplot1 = new XYPlot(data1, timeAxis, new NumberAxis("Price"), candle);
XYPlot subplot2 = new XYPlot(dataset2, timeAxis, new NumberAxis("Volume"), rr2);
CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis);
plot.add(subplot1, 3);
plot.add(subplot2, 1);
plot.setOrientation(PlotOrientation.VERTICAL);
// return a new chart containing the overlaid plot...
return new JFreeChart("CombinedDomainXYPlot Demo",
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
public Date[] getDTS(int n) {
Date[] dts = new Date[n];
for(int i=0; i<dts.length; i++) {
dts[i] = new Date(90,1,i);
}
return dts;
}
public double[] arr(int length, double v) {
double[] d = new double[length];
for(int i=0; i<d.length; i++) {
d[i] = v;
}
return d;
}
public static void main(final String[] args) {
final CombinedXYPlotDemo1 demo = new CombinedXYPlotDemo1("CombinedDomainXYPlot Demo");
demo.setSize(100, 100);
demo.setVisible(true);
}
}
And a big thanks to Dave for an excellent library.