slider labels and chart tick labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Hans Horn
Posts: 10
Joined: Mon Aug 04, 2008 10:39 pm

slider labels and chart tick labels

Post by Hans Horn » Mon Aug 04, 2008 10:45 pm

Group,

In my app I have a slider which I want to display the same tick labels as the domain axis of my chart uses.
However, I have not been able to find out how to access the ticklabels used by the axis.
Anybody has got any leads?
thx,
Hans

Hans Horn
Posts: 10
Joined: Mon Aug 04, 2008 10:39 pm

Post by Hans Horn » Wed Aug 06, 2008 3:09 pm

Well, I figured it out for myself.

I created a fake tick list using a fake screen data area and calling refreshTicks() on the axis such as:

Code: Select all

Rectangle2D fakeArea = new Rectangle2D.Double(10, 10, 1000, 1000);
java.util.List ticks = plot.getDomainAxis().refreshTicks((Graphics2D) chartPanel.getGraphics(), 
                                                null, fakeArea, RectangleEdge.BOTTOM);
String idx0 = ((NumberTick) ticks.get(0)).getText().replace(",","");
String idx1 = ((NumberTick) ticks.get(1)).getText().replace(",","");
int delta = Integer.parseInt(idx1) - Integer.parseInt(idx0);

slider.setMajorTickSpacing(delta);
That did the trick. If there is a better way, pls. let me know.

I don't know what others think, but my impression is that it appears to be unnecessarily hard to do certain simple things with JFreeChart (even tho I love using it).

kindly,
H.

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

Post by paradoxoff » Wed Aug 06, 2008 3:57 pm

If you want to get the entire tick list, your approach is probably as simple as it can be.
If all you want to get is the difference between two ticks (this is what you are calculating in your example), see this thread:
http://www.jfree.org/phpBB2/viewtopic.php?p=68718
Regards, paradoxoff

Hans Horn
Posts: 10
Joined: Mon Aug 04, 2008 10:39 pm

Post by Hans Horn » Wed Aug 06, 2008 8:10 pm

Yup,

but then I'd have to install a progress listener that would update my slider once the chart has been painted!

Tried that; for very large datasets I get some weird repainting issues on the slider when the initial ticklabels are being made in-sync with the chart.

Thx for responding,
H.

Locked