hi ,
in the following program I am generating a multiple axis time series, the tick units are not visible for the range xis whenever the data is as big as 10E7 . amy i know why is this happening and is there any way to circumvent the problem .This happens only for range axis .
import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.Spacer;
import org.jfree.chart.TextTitle;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.data.XYDataset;
import org.jfree.data.time.Minute;
import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.axis.TickUnits;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.axis.DateTickUnit;
public class MultipleAxisDemo1 extends ApplicationFrame {
public MultipleAxisDemo1(String title) {
super(title);
JFreeChart chart = createChart();
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));
chartPanel.setHorizontalZoom(true);
chartPanel.setVerticalZoom(true);
setContentPane(chartPanel);
}
private JFreeChart createChart() {
XYDataset dataset1 = createXYDataset3("Agricultural Land(Hectares)");
int i =100;
int j=0;
int k =0;
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Multiple Axis Demo 1",
"Time of Day",
"Primary Range Axis",
dataset1,
true,
true,
false
);
chart.setBackgroundPaint(Color.white);
chart.addSubtitle(new TextTitle("Debtor country AFG , Creditor country IMF, Debtor Type CENTRAL BANK Debtor country AFG , Creditor country IMF, Debtor Type CENTRAL BANK "));
XYPlot plot = chart.getXYPlot();
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
NumberAxis axis2 = (NumberAxis)plot.getRangeAxis();
NumberTickUnit nunit2 = new NumberTickUnit(1.0E8);
axis2.setTickUnit(nunit2);
StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
renderer.setPaint(Color.black);
renderer.setPlotShapes(true);
DateAxis daxis = (DateAxis) plot.getDomainAxis();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
DateTickUnit unit = new DateTickUnit(DateTickUnit.YEAR,1 , sdf);
daxis.setTickUnit(unit);
// AXIS 3
NumberAxis axis3 = new NumberAxis("");
NumberTickUnit nunit1 = new NumberTickUnit(3000);
axis3.setTickUnit(nunit1);
axis3.setLabelPaint(Color.green);
axis3.setTickLabelPaint(Color.green);
plot.setSecondaryRangeAxis(1, axis3);
plot.setSecondaryRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
XYDataset dataset3 = createXYDataset2("Agricultural machinery, tractors");
plot.setSecondaryDataset(1, dataset3);
plot.mapSecondaryDatasetToRangeAxis(1, new Integer(1));
plot.setSecondaryRenderer(1, new StandardXYItemRenderer());
StandardXYItemRenderer renderer1 = (StandardXYItemRenderer)plot.getSecondaryRenderer(1);
renderer1.setPaint(Color.green);
renderer1.setPlotShapes(true);
plot.getSecondaryRenderer(1).setSeriesPaint(0, new Color(i,j,k));
NumberAxis axis4 = new NumberAxis("ASF");
NumberTickUnit nunit3 = new NumberTickUnit(1.0E7);
axis4.setTickUnit(nunit3);
i=i+20;
j=j+40;
k= k+100;
axis4.setLabelPaint(Color.red);
axis4.setTickLabelPaint(Color.red);
plot.setSecondaryRangeAxis(2, axis4);
plot.setSecondaryRangeAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT);
XYDataset dataset4 = createXYDataset3("AGP");
plot.setSecondaryDataset(2, dataset4);
plot.mapSecondaryDatasetToRangeAxis(2, new Integer(2));
plot.setSecondaryRenderer(2, new StandardXYItemRenderer());
StandardXYItemRenderer renderer2 = (StandardXYItemRenderer)plot.getSecondaryRenderer(2);
renderer2.setPaint(Color.red);
renderer2.setPlotShapes(true);
plot.getSecondaryRenderer(2).setSeriesPaint(2,Color.red);
return chart;
}
private XYDataset createXYDataset1(String name) {
TimeSeries series = null;
RegularTimePeriod period = null;
double[] value={79,80 ,90 , 10 , 120 , 150 };
int year =1997;
series = new TimeSeries(name, (new org.jfree.data.time.Year()).getClass());
TimeSeriesCollection dataset = new TimeSeriesCollection();
for (int i = 0; i < 6; i++) {
year = year+2;
period = new org.jfree.data.time.Year(year);
series.add(period, value);
System.out.println("period="+period);
System.out.println("value="+value);
}
dataset.addSeries(series);
return dataset;
}
private XYDataset createXYDataset3(String name) {
TimeSeries series = null;
RegularTimePeriod period = null;
double[] value={38054000,38054000,38054000, 38054000,3805400, 38054000};
int year =1997;
series = new TimeSeries(name, (new org.jfree.data.time.Year()).getClass());
TimeSeriesCollection dataset = new TimeSeriesCollection();
for (int i = 0; i < 6; i++) {
year = year+2;
period = new org.jfree.data.time.Year(year);
series.add(period, value);
System.out.println("period="+period);
System.out.println("value="+value);
}
dataset.addSeries(series);
return dataset;
}
private XYDataset createXYDataset2(String name) {
TimeSeries series = null;
RegularTimePeriod period = null;
double[] value={2000,5000 , 4000 , 3000 , 7000};
int year =1997;
series = new TimeSeries(name, (new org.jfree.data.time.Year()).getClass());
TimeSeriesCollection dataset = new TimeSeriesCollection();
for (int i = 0; i < 5; i++) {
year = year+2;
period = new org.jfree.data.time.Year(year);
series.add(period, value);
System.out.println("period="+period);
System.out.println("value="+value);
}
dataset.addSeries(series);
return dataset;
}
public static void main(String[] args) {
MultipleAxisDemo1 demo = new MultipleAxisDemo1("Multiple Axis Demo 1");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
Thanks & Regards,
Murugan