XYDifferenceRenderer + percentage

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
peetzer
Posts: 11
Joined: Mon May 11, 2009 2:20 pm

XYDifferenceRenderer + percentage

Post by peetzer » Tue May 12, 2009 3:33 pm

Is it possible to use the XYDifferenceRenderer and show a percentage for example in the rangeaxis (or itemlabel) regarding the the two values that are compared?

I have no idea how I can combine the values without changing the whole dataset in percentages :(

Any suggestions? I like tot keep the XYDifferenceRenderer since it gives an nice overview....

Kinds regards Peter

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: XYDifferenceRenderer + percentage

Post by RichardWest » Tue May 12, 2009 6:11 pm

That is not as easy as you might think. The XYDifferenceRenderer does a lot of interpolating to eliminate the requirement that the two series being diffed share a common set of domain values. This leads to an interesting set of corner cases.

Creating a dataset with the values precomputed as percentages will probably work if you do indeed have a common set of domain values. If not, what two values do you use to compute the percentages at each point? The interpolated values? The previous values? etc. Let me think about this some more.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

peetzer
Posts: 11
Joined: Mon May 11, 2009 2:20 pm

Re: XYDifferenceRenderer + percentage

Post by peetzer » Wed May 13, 2009 7:15 am

Hi Richard, thank you for your response..

In the XYDifferenceRenderer I have two values, a maximum and a totalcount, both on a certain timeinterval.

On the the domain axis I show an interval on by example every half hour, so 00:00, 00:30, 01:00 etc.. to the end of the day

I would like to show the utilization in a percentage of the two values.. I have a totalcount of 1 and a maximum of 4, so a percentage of 25% at a certain timeinterval..

I know if I use percentage values in my dataset instead of the absolute numbers in a bar chart I can show the percentage.. but only the percentages...

I would like to show both (absolute numbers and percentages) and the XYDifferenceRenderer gives an idea in which free spaces are left or are overmaxed...

In the itemLabelPosition you have both axis values....

I know the series need to be related somehow..

XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{2}", decimalformat, decimalformat);

Let me know if there is something I could try :)

In regards to your question.. yes they share a common set of domain values in timeinterval parts....

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: XYDifferenceRenderer + percentage

Post by RichardWest » Wed May 13, 2009 7:59 pm

I do not really have any suggestions on how to use or adapt the XYDifferenceRenderer to suit your needs unless you create a second dataset with precomputed percentages. The rendering logic for the XYDifferenceRenderer is complex, and I would need to refactor a good amount to handle this case. Even if I do, I am not sure I can create a 'correct' model without injecting data which I am against in most instances.

One recommendation that I can give is that you create a bar chart and supply a custom renderer that colors the bars green if the totalcount is less than the maximum and red if the total count is greater. You can also add a ValueMarker to the domain axis to highlight the maximum assuming it is fixed. If the maximum is fixed, you can also create a custom dataset. The custom dataset's constructor would take your actual dataset and the value for the maximum. You can use both to compute the percentages on-the-fly in a overridden getY() and getYValue() methods.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

peetzer
Posts: 11
Joined: Mon May 11, 2009 2:20 pm

Re: XYDifferenceRenderer + percentage

Post by peetzer » Thu May 14, 2009 6:54 am

Thank you Richard, I have added another dataset based on the two values (double axis), so I can see both absolute numbers and percentages. It is ok for me :)

Locked