adding array of values to dataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anirudhak
Posts: 15
Joined: Thu Apr 30, 2009 11:06 am

adding array of values to dataset

Post by anirudhak » Thu May 14, 2009 8:22 am

hii,

i am new to jfree chart
is it possible to add array of (x , y ) values XYseries of the dataset
this is the work done by mee.,
but i am getting more bugs

Code: Select all

dataitems[] xypiont = new dataitems[10];
        	xypiont[0] = new dataitems(451, 3500);
        	xypiont[1] = new dataitems(452, 3600);
        	xypiont[2] = new dataitems(453, 3580);
        	xypiont[3] = new dataitems(454, 3620);
        	xypiont[4] = new dataitems(456, 3700);
        	xypiont[5] = new dataitems(458, 3800);
        	xypiont[6] = new dataitems(462, 3850);
            
            XYSeries series4 = new XYSeries("Series 3");
            for (int i =0 ; i< 6 ; i++){
            	
				int x = xydata[i].domainval; 
				double y = xydata[i].rangeval; 
				series4.add(x,y);
            }
            
            XYSeriesCollection dataset = new XYSeriesCollection();
            dataset.addSeries(series4); 
            return dataset ;

anirudhak
Posts: 15
Joined: Thu Apr 30, 2009 11:06 am

Re: adding array of values to dataset

Post by anirudhak » Thu May 14, 2009 8:24 am

is it the right process i did
please tell me..,
these r the bugs i got

Exception in thread "main" java.lang.NullPointerException
at jfreechart.HideSeriesDemo1$MyDemoPanel.createSampleDataset(HideSeriesDemo1.java:97)
at jfreechart.HideSeriesDemo1$MyDemoPanel.<init>(HideSeriesDemo1.java:37)
at jfreechart.HideSeriesDemo1.<init>(HideSeriesDemo1.java:157)
at jfreechart.HideSeriesDemo1.main(HideSeriesDemo1.java:183)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: adding array of values to dataset

Post by paradoxoff » Thu May 14, 2009 7:57 pm

Your dataitems class seems to do the same thing as the XYDataItem class, namely storing an x and an y value. Since the latter is a part of JFreeChart, I would strongly recommend to use it.
Note that you are filling an array called xypiont with dataitems, but you are accessing an array called xydata.

anirudhak
Posts: 15
Joined: Thu Apr 30, 2009 11:06 am

Re: adding array of values to dataset

Post by anirudhak » Fri May 15, 2009 7:52 am

thanks for ur reply ..,

this is my dataitems class .., is it the right way i declared.., please provide me with an example if i am wrong

Code: Select all

public class dataitemstest {
  
}

class dataitems {
   double domainval;

   double rangeval;

  public dataitems(double n, double s) {
	  domainval = n;
	  rangeval = s;
  }

  
}
Thanks ,
K.anirudh

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: adding array of values to dataset

Post by david.gilbert » Fri May 15, 2009 8:29 am

I think 'paradoxoff' was just saying that your 'dataitems' class is redundant, not that it is incorrect. He also points out another potential error you made, which is that you populate a temporary array called 'xypiont' with some data values, but then don't use that array to populate the XYSeries but use another array 'xydata' instead. Maybe 'xydata' is null and that's the cause of your NullPointerException.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked