how to colour area between 2 lines?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
theAnonymous
Posts: 11
Joined: Tue Feb 22, 2011 8:15 pm
antibot: No, of course not.

how to colour area between 2 lines?

Post by theAnonymous » Wed May 11, 2011 5:50 pm

hello, im trying to draw an ichimoku cloud.

http://www.swing-trade-stocks.com/image ... charts.png

so, how do i colour an area between 2 lines? thanks.

fatso83
Posts: 12
Joined: Thu May 12, 2011 1:41 pm
antibot: No, of course not.

Re: how to colour area between 2 lines?

Post by fatso83 » Thu May 12, 2011 1:50 pm

This would be very interesting for me as well. A typical application would be to plot a line with a line above and under showing how a graph develops +- one standard deviation. Fill the space between the upper and lower line with a fill color and voila, it looks quite nice. No clue as to how one actually should do this though ...

I can guess that one way would be to plot three graphs/pictures and then overlay them ontop of eachother somehow.

hedgefund@jnetonline
Posts: 1
Joined: Fri Sep 14, 2012 6:57 pm
antibot: No, of course not.

Re: how to colour area between 2 lines?

Post by hedgefund@jnetonline » Sat Sep 15, 2012 3:10 am

The Ichimoku Cloud can be drawn using XYDifferenceRenderer. The code goes like this:

Code: Select all

  /**
    * Adds plot of Kumo to an existing plot
    * @param plot an already created and initialized plot object, we will add Kumo to this plot
    * @param tsSenkouSpanA time series of "Leading Span A", which forms one edge of the cloud
    * @param tsSenkouSpanB time series of "Leading Span B", which forms the other edge of the cloud
    8?
  void drawKumo(XYPlot plot, TimeSeries tsSenkouSpanA, TimeSeries tsSenkouSpanB) {
    TimeSeriesCollection tsc = new TimeSeriesCollection();
    tsc.addSeries(tsSenkouSpanA);
    tsc.addSeries(tsSenkouSpanB);
    XYDifferenceRenderer xydr = new XYDifferenceRenderer();

    // Here I assume that "plot" does not have any other plots yet. Hence the following two lines are setting the data set
    // an the renderer for the 1st (zeroeth, as in zero-based systems) time series collection to be plotted.
    plot.setDataSet(0, tsc);
    plot.setRenderer(0, xydr);
  }
Note that by default when Senkou Span A is above Senkou Span B, then the color of the cloud would be green; when Senkou Span A is below Senkou Span B, then the color of the cloud is red. To change the color of the cloud, use XYDifferenceRenderer.setPositivePaint and XYDifferenceRenderer.setNegativePaint.

fatso83
Posts: 12
Joined: Thu May 12, 2011 1:41 pm
antibot: No, of course not.

Re: how to colour area between 2 lines?

Post by fatso83 » Sat Sep 15, 2012 9:28 am

As to what I was talking about, some code can be found here:
http://www.jfree.org/phpBB2/viewtopic.p ... 31#p167479

Locked