LevelRenderer: Lines Not Lining up over bars

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
TMazzotta
Posts: 40
Joined: Thu Mar 27, 2003 7:11 pm

LevelRenderer: Lines Not Lining up over bars

Post by TMazzotta » Thu Jun 04, 2015 7:20 pm

Hello.
I am using the 'LevelRenderer' class to show graphs like the one pictured below. I created this based on the demo posted here: http://www.java2s.com/Code/Java/Chart/J ... tDemo2.htm

But I've been getting feedback from my users that the lines showing the forecasted information aren't in the 'right' place. See notations in screenshot below.
Is there any way to improve this so it looks better?

Thanks in advance

tom

Image

TMazzotta
Posts: 40
Joined: Thu Mar 27, 2003 7:11 pm

Re: LevelRenderer: Lines Not Lining up over bars

Post by TMazzotta » Thu Jun 04, 2015 8:23 pm

I've figured this out:

When I am creating the vertical bars showing the actual market share numbers, I am making this call to the main renderer (for bars):
((BarRenderer) plot.getRenderer()).setItemMargin(0); //On the cluster bar charts, users noticed that the white space between the bars in a cluster is a wider than it used to be. They'd like the bars to be right next to each other.

If I remove this call, the level-lines line up, but this is not desired.

So I got around this by doing the following to the secondary renderer to ensure the item margins are the same for both renderers:
LevelRenderer levelRenderer = (LevelRenderer)plot.getRenderer(index);
levelRenderer.setItemMargin(0);

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: LevelRenderer: Lines Not Lining up over bars

Post by david.gilbert » Tue Jun 09, 2015 6:22 am

Glad you figured it out :-)
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

TMazzotta
Posts: 40
Joined: Thu Mar 27, 2003 7:11 pm

Re: LevelRenderer: Lines Not Lining up over bars

Post by TMazzotta » Fri Jun 12, 2015 6:34 am

Hi Dave -
I have a follow up question on this topic.

see screenshot below for what I'd like to do.

I've found the setMaximumItemWidth() method where I pass in the a % of the width of the entire chart , but I'd like to make it so it is a bit more flexible than that approach.
Meaning, the length of the levelLines is always just a tad smaller than the width of the bars.. That way if the bars are wide, the LevelLines grow but still stay less than the bar width.. Similarly , if bars are narrow, then the level Line length shrinks so it is just tad smaller.

One Idea I had was if I could figure out the width of the bars and the width of the chart and use that to determine a reasonable value to send to setMaximumItemWidth , For example, e say bar width is 10 units wide and chart is 100 units wide, then that says the bar width is 10% of the width of the chart.. Then I could just call the setMaximumItemWidth method on the LevelLineRender to be just a tad below 10% (ie 10%-2%). But this requires knowing 2 important pieces of info (bar width and chart width).

Hoping you or others could help me with either using this tact or another one to accomplish what I am looking for.

Image

Locked