XYLineAndShapeRenderer-has problem

A free public discussion forum for the JFreeChart class library.

XYLineAndShapeRenderer-has problem

Postby avirutha » Fri Jan 25, 2008 11:07 am

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
avirutha
 
Posts: 8
Joined: Mon Sep 24, 2007 7:19 am

Postby mickish » Fri Jan 25, 2008 3:21 pm

I am using XYPlot, XYDataset, and XYLineAndShapeRenderer, too.

Zoom does not work well for me, either. When using a LogAxis for the range, zoom never draws the series lines, even though the domain and range axis labels change appropriately.

Zoom works better with a NumberAxis for the range.
mickish
 
Posts: 29
Joined: Tue Jan 08, 2008 11:15 pm
Location: Venice, Florida

Postby david.gilbert » Mon Jan 28, 2008 6:38 pm

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.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11316
Joined: Fri Mar 14, 2003 10:29 am

Postby mickish » Wed Feb 13, 2008 8:07 pm

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;
       }                  
};
mickish
 
Posts: 29
Joined: Tue Jan 08, 2008 11:15 pm
Location: Venice, Florida

Postby avirutha » Fri Feb 22, 2008 10:37 am

Its not working . i still face the same problem while zooming
avirutha
 
Posts: 8
Joined: Mon Sep 24, 2007 7:19 am

Postby unknownfrog » Wed Mar 26, 2008 3:22 pm

Hi,

I had the same problem here. The above workaround works here, but the performance penalty is obvious. Switching off drawing as linepath would also solve the problem with a large dataset and a dash pattern this results in a dowdy drawing.

Tom
unknownfrog
 
Posts: 6
Joined: Thu Mar 20, 2008 5:38 pm

Postby skunk » Sun Jul 27, 2008 5:00 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
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;
}


2. Insert the following into org/jfree/chart/plot/XYPlot.java
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,


3. Modify the following 3 blocks of code in org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java
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    }


Voila! Now the obvious benefits of the DrawSeriesLineAsPath optimization can be used even when the chart is zoomed / scrolled.
skunk
 
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

StandardXYItemRenderer and setGapThreshold

Postby Mike Watts » Mon Jul 28, 2008 2:57 pm

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
Mike Watts
 
Posts: 13
Joined: Mon May 08, 2006 1:27 pm

Postby skunk » Mon Jul 28, 2008 4:28 pm

You need to add null / NaN values in your dataset if you want non-continuous lines to be plotted
skunk
 
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Postby Mike Watts » Mon Jul 28, 2008 5:03 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.
Mike Watts
 
Posts: 13
Joined: Mon May 08, 2006 1:27 pm

Postby skunk » Mon Jul 28, 2008 6:15 pm

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);"
skunk
 
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Postby Mike Watts » Tue Jul 29, 2008 9:43 am

Thanks for that - useful to know. I'll remove reference to that class which may fix a few problems I suspect :-)
Mike Watts
 
Posts: 13
Joined: Mon May 08, 2006 1:27 pm

Disappearing Traces

Postby Mike Watts » Fri Aug 15, 2008 4:22 pm

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...
Mike Watts
 
Posts: 13
Joined: Mon May 08, 2006 1:27 pm

Postby skunk » Fri Aug 15, 2008 5:57 pm

No problems. Hopefully this fix will make it into an official release soon.
skunk
 
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

fix of shunk in 1.0.11

Postby unknownfrog » Wed Oct 29, 2008 10:45 am

Hi,

is the fix provided by skunk integrated into the 1.0.11 Version?

Tom
unknownfrog
 
Posts: 6
Joined: Thu Mar 20, 2008 5:38 pm

Next

Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], Yahoo [Bot] and 9 guests

cron