NullPointer w/ areachart and time axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kulsi
Posts: 7
Joined: Sat Nov 20, 2004 7:53 pm

NullPointer w/ areachart and time axis

Post by kulsi » Mon May 30, 2005 6:44 pm

I have went over the posts on using a stacked area chart with a time series and have tried to follow those models. I will try to explain first without pasting the code. I am using TableXYDataset with createStackedXYAreaChart.
I create the panel first and within this:

Seconds seconds = new Second();

TableXYDataset data = createDatasets("title", seconds);

JFreeChart chart1 = createChart("title", data);

For creating the dataset function, I have tried two ways:
1) Using the TimeSeries class, and adding values to the series with its corresponding time (series.add(seconds,value)). Then Using TimeSeriesCollection dataset = new TimeseriesCollection() and dataset.addSeries(series) and returning the dataset.
2)Using dataset = new TimeTableXYDatatset, and then dataset.add(seconds, value, "series") and returning the dataset.


For creating the chart:
ChartFactory.createStackedXYAreaChart etc...

I have XYPlot plot,
I used the XYPlot methods for setting various colors, but commented some out because I was getting NullPointerExceptions in this area of code. I do have plot.setRenderer(new StackedXYAreaRenderer) but this did not help either.
THen I also have a DateAxis axis object.
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));
axis.setAutoRange(true);
and I return the chart.

So basically, my NullPointerException stack is as follows:
Exception in thread "main" java.lang.NullPointerException
at StackedAreaChartIP.createChart(StackedAreaChartIP.java:404)
at StackedAreaChartIP.createPanel(StackedAreaChartIP.java:141)
at StackedAreaChartIP.<init>(StackedAreaChartIP.java:119)
at StackedAreaChartIP.main(StackedAreaChartIP.java:532)

line 404 occurs when I try to use any XYPlot method with the plot object. line 141 occurs at JFreeChart chart1 = createChart("title", data);
line 119 occurs in the constructor when I call createPanel();
line 532 occurs in main where I have StackedAreaChartIP demo = new StackedAreaChartIP() -- This is the name of my class, and I have a constructor that takes in no arguements and calls the createPanel() method.

I can paste the code, but thought that would make this post too long and perhaps was not necessary.

Thanks

kulsi
Posts: 7
Joined: Sat Nov 20, 2004 7:53 pm

Post by kulsi » Sun Jun 05, 2005 4:16 pm

ok, so up till now, I *think* no more exceptions.. but now when I run the program, absolutely nothing happens.

if anyone has some code sample that creates the stacked area chart with time series data (or at least time on the x axis) please let me know and I can work the rest on my own. I have looked over the code in the demo, but none of those X axis has time. I have been through every post in the forum that talks about stacked or timetablexydataset or even tablexydataset.

Any help would be appreciated.. thanks.

Locked