XYLineAndShapeRenderer-has problem
XYLineAndShapeRenderer-has problem
Iam using XYLineAndShapeRenderer to set linestyle in xyseries plot sinc dotted line style is not visible with XYItemrender .I have used XYLineAndShapeRendere.setDrawSeriesLineAsPath(true);to resolve the issue.
The problem now is when zooming the chart, the curves are disappearing.
Can anyone help me
The problem now is when zooming the chart, the curves are disappearing.
Can anyone help me
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
The first problem, at least, is a bug in an optimisation introduced in JFreeChart 1.0.6, where the renderer tries to process only the items that are visible in the chart (which can save a lot of processing if the data items are ordered by x-value).
The problem is that the drawSeriesLineAsPath option assumes that the renderer will be passed the 0 and N-1 items. With the optimisation, that doesn't actually happen when the plot is zoomed in. The quick fix is to call state.setProcessVisibleItemsOnly(false) in the renderer's initialise() method. I'll try to find a fix that will retain the optimisation.
The problem is that the drawSeriesLineAsPath option assumes that the renderer will be passed the 0 and N-1 items. With the optimisation, that doesn't actually happen when the plot is zoomed in. The quick fix is to call state.setProcessVisibleItemsOnly(false) in the renderer's initialise() method. I'll try to find a fix that will retain the optimisation.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Thanks, that worked!
Code: Select all
final XYLineAndShapeRenderer rendererXYLineAndShape =
new XYLineAndShapeRenderer(true, false) {
/**
* Compensate for Zoom bug with LogAxis
* http://www.jfree.org/phpBB2/viewtopic.php?t=23673
*/
@Override
public XYItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
XYPlot plot,
XYDataset data,
PlotRenderingInfo info) {
final XYItemRendererState state =
super.initialise(g2, dataArea, plot, data, info);
state.setProcessVisibleItemsOnly(false);
return state;
}
};
-
- Posts: 6
- Joined: Thu Mar 20, 2008 5:38 pm
Seeing that it was my optimization that caused DrawSeriesLineAsPath to break, here is a patch to fix it (All line numbers in this post refer to the 1.0.10 sources)
1. Add the following to org/jfree/chart/renderer/xy/XYItemRendererState.java
2. Insert the following into org/jfree/chart/plot/XYPlot.java
3. Modify the following 3 blocks of code in org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java
Voila! Now the obvious benefits of the DrawSeriesLineAsPath optimization can be used even when the chart is zoomed / scrolled.
1. Add the following to org/jfree/chart/renderer/xy/XYItemRendererState.java
Code: Select all
private transient int firstItemIndex;
private transient int lastItemIndex;
public void setFirstItemIndex(int first) {
firstItemIndex = first;
}
public void setLastItemIndex(int last) {
lastItemIndex = last;
}
public int getFirstItemIndex() {
return firstItemIndex;
}
public int getLastItemIndex() {
return lastItemIndex;
}
Code: Select all
3345 int[] itemBounds = RendererUtilities.findLiveItems(
3346 dataset, series, xAxis.getLowerBound(),
3347 xAxis.getUpperBound());
3348 firstItem = itemBounds[0];
3349 lastItem = itemBounds[1];
3350 }
state.setFirstItemIndex(firstItem);
state.setLastItemIndex(lastItem);
3351 for (int item = firstItem; item <= lastItem; item++) {
3352 renderer.drawItem(g2, state, dataArea, info,
3353 this, xAxis, yAxis, dataset, series, item,
===============================================
3367 int[] itemBounds = RendererUtilities.findLiveItems(
3368 dataset, series, xAxis.getLowerBound(),
3369 xAxis.getUpperBound());
3370 firstItem = itemBounds[0];
3371 lastItem = itemBounds[1];
3372 }
state.setFirstItemIndex(firstItem);
state.setLastItemIndex(lastItem);
3373 for (int item = firstItem; item <= lastItem; item++) {
3374 renderer.drawItem(g2, state, dataArea, info,
3375 this, xAxis, yAxis, dataset, series, item,
Code: Select all
875 // first pass draws the background (lines, for instance)
876 if (isLinePass(pass)) {
877 // if (item == 0) {
if (item == state.getFirstItemIndex()) {
878 if (this.drawSeriesLineAsPath) {
879 State s = (State) state;
===============================================
960 // if (item == 0) {
if (item == state.getFirstItemIndex()) {
961 return;
962 }
===============================================
1081 // if this is the last item, draw the path ...
1082 // if (item == dataset.getItemCount(series) - 1) {
if (item == state.getLastItemIndex()) {
1083 // draw path
1084 drawFirstPassShape(g2, pass, series, item, s.seriesPath);
1085 }
-
- Posts: 13
- Joined: Mon May 08, 2006 1:27 pm
StandardXYItemRenderer and setGapThreshold
Hi - I have a problem with the StandardXYItemRenderer if I call setDrawSeriesLineAsPath(true) in that the gap threshold is ignored - it always joins up lines.
I tried the mods suggested above ( state.setProcessVisibleItemsOnly(false) and those posted by skunk, but neither make a difference for the gap threshold.
Any ideas?
Mike Watts
I tried the mods suggested above ( state.setProcessVisibleItemsOnly(false) and those posted by skunk, but neither make a difference for the gap threshold.
Any ideas?
Mike Watts
-
- Posts: 13
- Joined: Mon May 08, 2006 1:27 pm
Thanks for that - that may be the way forward, and as I am probably the only person using setThreshold etc it may be quicker examining the data and inserting null data points rather than trying to fix JFreeChart's threshold feature. If that is the answer then the methods associated with thresholds should be deprecated to prevent others falling into the same trap.
Sorry, I misread your original post. This thread is about XYLineAndShapeRenderer. As far as I am aware, StandardXYItemRenderer is (soon to be?) deprecated. The javadoc states
"This renderer has been retained for historical reasons and, in general, you should use the XYLineAndShapeRenderer class instead. "
The only thing I can suggest is checking the value of gapThresholdType, which (according to the comments in the source) was your suggestion
"* 08-Oct-2004 : Added 'gapThresholdType' as suggested by Mike Watts (DG);"
"This renderer has been retained for historical reasons and, in general, you should use the XYLineAndShapeRenderer class instead. "
The only thing I can suggest is checking the value of gapThresholdType, which (according to the comments in the source) was your suggestion
"* 08-Oct-2004 : Added 'gapThresholdType' as suggested by Mike Watts (DG);"
-
- Posts: 13
- Joined: Mon May 08, 2006 1:27 pm
-
- Posts: 13
- Joined: Mon May 08, 2006 1:27 pm
Disappearing Traces
I had a case of 'disappearing traces' where I would choose a particular region ( in time ) and the traces would not be shown but, zooming on on the area would show them or you could see tooltips popping up at the data points. My data has gaps that need to be shown so I have now implemented a routine to insert null points where the gap is longer than the threshold and it was only on portions where there was a null that the problem appeared, but not in all cases.
Just wanted to report that I tried the changes posted by skunk above and to my utter relief they have fixed the problem, or at least so far I haven't managed to break it again. Thanks for that skunk, I was pretty much about to throw it in and use another graph component. All we need to do now is fix the date axis...
Just wanted to report that I tried the changes posted by skunk above and to my utter relief they have fixed the problem, or at least so far I haven't managed to break it again. Thanks for that skunk, I was pretty much about to throw it in and use another graph component. All we need to do now is fix the date axis...
-
- Posts: 6
- Joined: Thu Mar 20, 2008 5:38 pm
fix of shunk in 1.0.11
Hi,
is the fix provided by skunk integrated into the 1.0.11 Version?
Tom
is the fix provided by skunk integrated into the 1.0.11 Version?
Tom