Draw Rectangle on graph

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
The_Wirjy
Posts: 3
Joined: Wed Mar 18, 2015 5:05 pm
antibot: No, of course not.

Draw Rectangle on graph

Post by The_Wirjy » Wed Mar 18, 2015 5:28 pm

Hi,

I make an application at school. This app must show the area under a function by drawing rectangles, trapezium or with the Simpson method.

Is there a way to draw rectangle on the graph like this :

Image
http://imgur.com/mUcowS5

Thank's

(Sorry for my english, I speak french)

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Draw Rectangle on graph

Post by paradoxoff » Thu Mar 19, 2015 1:12 pm

Do you want to show the grey bars or the red circle on the chart?

The_Wirjy
Posts: 3
Joined: Wed Mar 18, 2015 5:05 pm
antibot: No, of course not.

Re: Draw Rectangle on graph

Post by The_Wirjy » Thu Mar 19, 2015 1:24 pm

I want to show the grey bars. Actually, I have the red line (a sinus function) and i want to draw the grey rectangles.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Draw Rectangle on graph

Post by paradoxoff » Thu Mar 19, 2015 5:42 pm

Do you already have the height of the bars that you want to plot, and their start and end values on the x-axis?
Then, I suggest to use a second dataset, eventually plotted to a secondary y-axis.

The_Wirjy
Posts: 3
Joined: Wed Mar 18, 2015 5:05 pm
antibot: No, of course not.

Re: Draw Rectangle on graph

Post by The_Wirjy » Fri Mar 20, 2015 10:58 am

A rectangle is defined like this :

start point : (x,0)
width : ((x+delta) - x) delta is the difference between two point on the sinus
height : f(x) : f represent the sinus function

Image

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Draw Rectangle on graph

Post by paradoxoff » Fri Mar 20, 2015 4:25 pm

Then just use an XYIntervalSeriesCollection as secondary dataset. You can plot that to the same axis as the first dataset, since the x and y values will be quite similar.

Locked