Connect line ignoring null/missing points

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kash22
Posts: 5
Joined: Thu May 04, 2006 10:30 am

Connect line ignoring null/missing points

Post by kash22 » Thu May 04, 2006 10:40 am

I have the following dataset for which i am drawing a line-chart:
There is no data/value for sample1 + ratio3.
The resultant chart shows the the disconnected/broken line on the chart.
What i would like is to do is to connect the previous and the next points, ignoring the above mentioned missing point.
Is is possible :?:
Thanks in advance..

Code: Select all

String sample1 = "Sample 1";
String sample2 = "Sample 2";
String sample3 = "Sample 3";
String ratio1 = "2:0.0";
String ratio2 = "2:0.5";
String ratio3 = "2:1.0";
String ratio4 = "2:1.5";
String ratio5 = "2:2.0";
String ratio6 = "2:2.5";
String ratio7 = "2:3.0";
String ratio8 = "2:3.5";
		DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
		defaultcategorydataset.addValue(new Double(1.0), sample1, ratio1);
		defaultcategorydataset.addValue(new Double(3.0), sample1, ratio2);
//No data for sample1 ratio3
//		defaultcategorydataset.addValue(new Double(5.0), sample1, ratio3);
		defaultcategorydataset.addValue(new Double(9.0), sample1, ratio4);
		defaultcategorydataset.addValue(new Double(11.0), sample1, ratio5);
		defaultcategorydataset.addValue(new Double(12.0), sample1, ratio6);
		defaultcategorydataset.addValue(new Double(14.0), sample1, ratio7);
		defaultcategorydataset.addValue(new Double(17.0), sample1, ratio8);

		defaultcategorydataset.addValue(new Double(2.0), sample2, ratio1);
		defaultcategorydataset.addValue(new Double(4.0), sample2, ratio2);
		defaultcategorydataset.addValue(new Double(6.0), sample2, ratio3);
		defaultcategorydataset.addValue(new Double(8.0), sample2, ratio4);
		defaultcategorydataset.addValue(new Double(9.0), sample2, ratio5);
		defaultcategorydataset.addValue(new Double(12.0), sample2, ratio6);
		defaultcategorydataset.addValue(new Double(13.0), sample2, ratio7);
		defaultcategorydataset.addValue(new Double(17.0), sample2, ratio8);
		defaultcategorydataset.addValue(new Double(1.0), sample3, ratio1);
		defaultcategorydataset.addValue(new Double(2.0), sample3, ratio2);
		defaultcategorydataset.addValue(new Double(3.0), sample3, ratio3);
		defaultcategorydataset.addValue(new Double(5.0), sample3, ratio4);
		defaultcategorydataset.addValue(new Double(7.0), sample3, ratio5);
		defaultcategorydataset.addValue(new Double(11.0), sample3, ratio6);
		defaultcategorydataset.addValue(new Double(13.0), sample3, ratio7);
		defaultcategorydataset.addValue(new Double(17.0), sample3, ratio8);
kash

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

Post by david.gilbert » Tue May 09, 2006 10:24 am

You have two options:

(1) Insert a value for (sample1, ratio3) that is the interpolated value you'd like to see plotted;

(2) Create a new renderer that handles null values by interpolating the value.

I think (2) is a cleaner solution - (1) requires polluting your dataset with "dummy" values, which is usually a bad thing to do.
David Gilbert
JFreeChart Project Leader

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

kash22
Posts: 5
Joined: Thu May 04, 2006 10:30 am

Thanks

Post by kash22 » Thu May 11, 2006 5:44 am

Thanks David, Option 2 is the one I shall be working on...
*This forum is great..*
Shall post any more queries if I have difficulty implementing it.. :)
kash

jtigner
Posts: 3
Joined: Thu Jun 15, 2006 5:11 pm

Render Null values as 0

Post by jtigner » Thu Jun 15, 2006 5:16 pm

david.gilbert wrote: (2) Create a new renderer that handles null values by interpolating the value.

I think (2) is a cleaner solution ...
I need to implement the same solution. I spent some time searching and couldn't find where to start.

I'm currently using an XYLineAndShapeRenderer and want null values to be drawn as if they were 0.

What class do I need to look at extending and/or implementing to accomplish this?

Thanks,
jtigner

jtigner
Posts: 3
Joined: Thu Jun 15, 2006 5:11 pm

Would it help?

Post by jtigner » Mon Jun 19, 2006 6:08 pm

Would it help if I mentioned that I'm more than willing to do the work, if I could just get pointed in the right direction.

To elaborate:

I have a series of results spanning several days. However, some results to not have entries for all days. So I may not get any results for March 25th for one dataset, but other datasets will have data on March 25th. Part of the problem is probably the way I'm building the chart, but it is the best solution I've come up with.

Instead of having the lack of data (null value) on March 25th cause a break in the dataset rendering, I would like to have it draw it as if there was a 0 value in there.

David mentioned creating a new renderer that handles null values, and this sounds like the best solution for me .. however, I'm not sure what classes and/or interfaces I need to be looking at extending to get started.

Thanks for any help you can provide,
jtigner

yazrop44
Posts: 2
Joined: Thu Jun 22, 2006 3:19 pm

JfreeChart MVC

Post by yazrop44 » Thu Jun 22, 2006 3:24 pm

Bonjour tout le monde, est ce que quelcun peut il m'aider pour implenter
l'API JfreeChart en architecture MVC.
Je vous remerci.

yazrop44
Posts: 2
Joined: Thu Jun 22, 2006 3:19 pm

JfreeChart MVC

Post by yazrop44 » Thu Jun 22, 2006 3:38 pm

Bonjour tout le monde, est ce que quelcun peut il m'aider pour implenter
l'API JfreeChart en architecture MVC.
Je vous remerci.

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

Re: Would it help?

Post by david.gilbert » Thu Jun 22, 2006 5:28 pm

jtigner wrote:Instead of having the lack of data (null value) on March 25th cause a break in the dataset rendering, I would like to have it draw it as if there was a 0 value in there.

David mentioned creating a new renderer that handles null values, and this sounds like the best solution for me .. however, I'm not sure what classes and/or interfaces I need to be looking at extending to get started.
The simplest solution is just to run through your dataset and replace null values with zeroes.

Alternatively, you could modify the XYLineAndShapeRenderer to make null values equal to zero. Look in the following methods that return early when they encounter null values...instead of returning, just set the values to zero:

drawPrimaryLine(...);
drawPrimaryLineAsPath(...);
drawSecondaryPass(...);
David Gilbert
JFreeChart Project Leader

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

jtigner
Posts: 3
Joined: Thu Jun 15, 2006 5:11 pm

Thanks!

Post by jtigner » Fri Jun 23, 2006 3:53 pm

That's what I needed. Thanks so much David.

Worked like a charm.

Thanks,
jtigner

Locked