Curve plot filling the integral area of specific peaks

A free public discussion forum for the JFreeChart class library.

Curve plot filling the integral area of specific peaks

Postby stavang » Mon Apr 16, 2007 11:28 am

Hello,

I have a curved graph, with several peaks, and I want to fill the integral area of some of the peaks

Example:
Image

My first thought was to define one dataset for the graph. The peaks I would render by using a XYDifferenceRenderer and one dataset per peak.

My first example has two peaks, filling the area of one peak:
Code: Select all
public class Test {
   public static void main(String[] args) {
      new Test();
   }

   /**
    * Default Empty Constructor
    */
   public Test() {

      ValueAxis timeAxis = new NumberAxis("Time");
      timeAxis.setLowerMargin(0.02);
      timeAxis.setUpperMargin(0.02);
      NumberAxis valueAxis = new NumberAxis("Value");
      valueAxis.setAutoRangeIncludesZero(false);
      XYPlot lPlot = new XYPlot(getXYDataSet_Values(), timeAxis, valueAxis, null);
      lPlot.setRenderer(new DefaultXYItemRenderer());
         lPlot.setDataset(1, getXYDataSet_FirstPeak());
         lPlot.setRenderer(1, new XYDifferenceRenderer(
               Color.green, Color.red, false));
     
      JFreeChart freeChart = new JFreeChart("Trend",
         JFreeChart.DEFAULT_TITLE_FONT, lPlot, true);
     
      ChartPanel chartPanel_Ctrl = new ChartPanel(freeChart);
      JFrame frame = new JFrame();
      frame.getContentPane().add(chartPanel_Ctrl);
      frame.pack();
      frame.setVisible(true);
   }

   private XYDataset getXYDataSet_FirstPeak() {
      DefaultXYDataset set = new DefaultXYDataset();
      set.addSeries("Series2", new double[][] {
            {
                  1, 2, 3
            }, {
                  0, 1, 0
            }
      });
      set.addSeries("series3", new double[][] {
            {
                  1, 2, 3
            }, {
                  0, 0, 0
            }
      });
      return set;
   }

   private XYDataset getXYDataSet_Values() {
      DefaultXYDataset set = new DefaultXYDataset();
      set.addSeries("Series1", new double[][] {
            {
                  0, 1, 2, 3, 4, 5, 6, 7
            }, {
                  0, 0, 1, 0, 0, 1, 0, 0
            }
      });
      return set;
   }
}

The problem is, that I get the labels of series2 and series3 (the Peak area) in the Legend, which is not what I want. Any clever solution to this?
stavang
 
Posts: 10
Joined: Mon Jan 22, 2007 2:05 pm

Postby RichardWest » Mon Apr 16, 2007 5:26 pm

If you are willing to be patient for a few days, I will probably have a solution that will work for you. I have been working with David Gilbert offline on a new XYDifferenceRenderer which removes several of the limitations of the old renderer. One limitation I had not considered was requiring two series (the minuend and subtrahend). In your case, your series is the minuend, and "zero" is the subtrahend. Of course, "zero" is implied by your lack of a second series which I feel is a good implication in this case. I will be emailing David with updated code, but I would be interested to hear his public opinion on this as well as when you might be able to see it in the repository.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Postby RichardWest » Mon Apr 16, 2007 7:09 pm

I have emailed David Gilbert a copy of the updated renderer with this added.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Postby david.gilbert » Tue Apr 17, 2007 10:30 am

I have Richard's code (thanks Richard!) and will try to get it integrated into CVS by the end of the week.

You might also try the setFixedLegendItems() method in the XYPlot class to remove those unwanted series labels.
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: 11352
Joined: Fri Mar 14, 2003 10:29 am

Postby stavang » Tue Apr 17, 2007 2:31 pm

Hello,

thanks for the replies. The setFixedLegendItems() did the trick for me.

@RichardWest
I'm a patient man, so I will even wait for the next version :wink:.
stavang
 
Posts: 10
Joined: Mon Jan 22, 2007 2:05 pm

Postby RichardWest » Mon Apr 23, 2007 7:02 pm

stavang wrote:Hello,

thanks for the replies. The setFixedLegendItems() did the trick for me.

@RichardWest
I'm a patient man, so I will even wait for the next version :wink:.


David uploaded my code/patch to the CVS repository if you wish to try it out. It was committed as revision 1.12.2.12 of XYDifferenceRenderer.java. For the effect you are looking for, create an XYDataset with only your data series and a transparent color (e.g. new Color(0, 0, 0, 0); // transparent black) for the negative paint color. Let me know how it goes. If you would like to wait for the next version of JFreeChart, David said this would be included in the 1.0.6 release (thanks David).
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Postby stavang » Wed May 16, 2007 9:44 am

I think I will wait for the 1.0.6 version, since I already have a workaround. When will it be released?
stavang
 
Posts: 10
Joined: Mon Jan 22, 2007 2:05 pm

Postby RichardWest » Wed May 16, 2007 6:55 pm

stavang wrote:I think I will wait for the 1.0.6 version, since I already have a workaround. When will it be released?


Unless David has changed his plans, 1.0.6 should be out within a month.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
RichardWest
 
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Postby david.gilbert » Thu May 17, 2007 2:25 pm

My original aim was to release 1.0.6 by the end of May, but I've been drawn into a little side project so the release may slip into June.
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: 11352
Joined: Fri Mar 14, 2003 10:29 am

Postby stavang » Fri May 18, 2007 11:17 am

I just discovered XYItemRenderer.setSeriesVisibleInLegend method, which is better to use than setFixedLegendItems in my case.
stavang
 
Posts: 10
Joined: Mon Jan 22, 2007 2:05 pm


Return to JFreeChart - General

Who is online

Users browsing this forum: Google [Bot] and 5 guests