For plotting data points (one per minute) which have a high degree of random variation, I'd like to use what GNUplot calls "impulse" presentation. Instead of connecting successive points to form a line graph, each point would have a purely vertical line reaching up to it from the x-axis.
In a mathematical sense at least, this sounds like a limiting case of a time-series bar graph, as the bar width approaches one pixel. Is that the most practical way to accomplish it, or could it be done more efficiently by extending StandardXYItemRenderer's current {LINES, SHAPES, IMAGES,DISCONTINUOUS} set of options?
Thanks,
Irv Thomae
Imitating GNUPlot's "Impulse" format?
Re: Imitating GNUPlot's "Impulse" format?
Hi Irv,
I would just create a new implementation of the XYItemRenderer, because I think the StandardXYItemRenderer is already overloaded. It's easy enough to switch from one renderer to another, so there's not really a need for one renderer to have lots of different options the way that StandardXYItemRenderer does now.
I'm about to check into CVS a new renderer (XYDotRenderer) that just draws dots at each x,y point, instead of trying to draw a shape or line or anything fancy. It would be pretty easy to copy and modify that class to draw a vertical line as you suggest.
Regards,
DG.
I would just create a new implementation of the XYItemRenderer, because I think the StandardXYItemRenderer is already overloaded. It's easy enough to switch from one renderer to another, so there's not really a need for one renderer to have lots of different options the way that StandardXYItemRenderer does now.
I'm about to check into CVS a new renderer (XYDotRenderer) that just draws dots at each x,y point, instead of trying to draw a shape or line or anything fancy. It would be pretty easy to copy and modify that class to draw a vertical line as you suggest.
Regards,
DG.
Re: Imitating GNUPlot's "Impulse" format?
Hi,
Is it possible to draw a Trend Line using This JFreeChart.
thanks,
Kishore.
Is it possible to draw a Trend Line using This JFreeChart.
thanks,
Kishore.
Re: Imitating GNUPlot's "Impulse" format?
Hi Dave,
Just today I found time to implement the suggestion yo made a week ago: namely, to extend XYDotRenderer.
I "wrote" a new class called "XYImpulseRenderer", which is an almost exact copy of XYDotRenderer, with just one change:
Within drawItem( lots of parameters), the XYDotRenderer class has
double transX = domainAxis.translateValueToJava2D(x, dataArea);
double transY = rangeAxis.translateValueToJava2D(y, dataArea);
g2.drawRect( (int)transX, (int)transY, 1,1);
Seeing that this draws the point as a 1 x 1 "rectangle", I simply substituted
g2.drawRect( (int)transX, (int)transY, 1,(int)transY);
to draw a "Rectangle" 1 unit wide but as high as the point's position.
And it works - mostly. However, some of the vertical lines thus created are broken up into 2 or more "pieces", with substantial amounts of white space between their successive parts. Visually, these breaks don't show much of a pattern - they look quite random, _not_ (for example) as if a constant-width band of white had been drawn across them. Taller lines are affected much more than shorter ones, but that's the only generalization I can make.
Can you shed any light on this mystery?
Thanks,
Irv
Just today I found time to implement the suggestion yo made a week ago: namely, to extend XYDotRenderer.
I "wrote" a new class called "XYImpulseRenderer", which is an almost exact copy of XYDotRenderer, with just one change:
Within drawItem( lots of parameters), the XYDotRenderer class has
double transX = domainAxis.translateValueToJava2D(x, dataArea);
double transY = rangeAxis.translateValueToJava2D(y, dataArea);
g2.drawRect( (int)transX, (int)transY, 1,1);
Seeing that this draws the point as a 1 x 1 "rectangle", I simply substituted
g2.drawRect( (int)transX, (int)transY, 1,(int)transY);
to draw a "Rectangle" 1 unit wide but as high as the point's position.
And it works - mostly. However, some of the vertical lines thus created are broken up into 2 or more "pieces", with substantial amounts of white space between their successive parts. Visually, these breaks don't show much of a pattern - they look quite random, _not_ (for example) as if a constant-width band of white had been drawn across them. Taller lines are affected much more than shorter ones, but that's the only generalization I can make.
Can you shed any light on this mystery?
Thanks,
Irv
Re: Imitating GNUPlot's "Impulse" format?
Irv,
I'm not sure, but I think your problem could be artifacts due to antialiasing. If you turn off antialiasing do they change/disappear?
Tom.
I'm not sure, but I think your problem could be artifacts due to antialiasing. If you turn off antialiasing do they change/disappear?
Tom.
Re: Imitating GNUPlot's "Impulse" format?
Tom,
Thanks for the suggestion. I just tried this:
// .... immediately after JFreeChart chart = ChartFactory.createXXX() :
chart.setAntiAlias(false);
Unfortunately, it seems to make no difference.
AFAIK, nobody has ever reported gaps in a vertical axis, although thta of course is drwn as a line. Apparently it's a bad idea to draw these vertical lines as "rectangles", though I can't see why that should be true....
Thanks for the suggestion. I just tried this:
// .... immediately after JFreeChart chart = ChartFactory.createXXX() :
chart.setAntiAlias(false);
Unfortunately, it seems to make no difference.
AFAIK, nobody has ever reported gaps in a vertical axis, although thta of course is drwn as a line. Apparently it's a bad idea to draw these vertical lines as "rectangles", though I can't see why that should be true....
Re: Imitating GNUPlot's "Impulse" format?
Hi Irv,
You could probably use a Line2D or g2.drawLine(...) and see if that makes the problem go away.
Regards,
DG
You could probably use a Line2D or g2.drawLine(...) and see if that makes the problem go away.
Regards,
DG
Re: Imitating GNUPlot's "Impulse" format?
Hi David,
Yes, Line2D(..) does make the problem go away, as does g2.drawLine(..), and the latter seems to be about 10% faster.
To save anybody else the same frustration, I'll confess that the first time I tried to use either g2.drawLine or g2.draw(new Line2D.Double(...) , I wrote the arguments as (transX, transY, transX, 0) - and couldn't understand why the entire plot was filled in. Of course, I had overlooked the need to translate my 0 to Java2D coordinates.
XYDotRenderer is a nice clean substitute for XYItemRenderer, but it does lack the latter's ability to use a logarithmic vertical axis. Do you expect to extend it in that way any time soon?
Thanks,
Irv
Yes, Line2D(..) does make the problem go away, as does g2.drawLine(..), and the latter seems to be about 10% faster.
To save anybody else the same frustration, I'll confess that the first time I tried to use either g2.drawLine or g2.draw(new Line2D.Double(...) , I wrote the arguments as (transX, transY, transX, 0) - and couldn't understand why the entire plot was filled in. Of course, I had overlooked the need to translate my 0 to Java2D coordinates.
XYDotRenderer is a nice clean substitute for XYItemRenderer, but it does lack the latter's ability to use a logarithmic vertical axis. Do you expect to extend it in that way any time soon?
Thanks,
Irv