Hi
I am currently trying to implement a linechart, but this also applies to other charts.
I just realize that my labels are not unique so can't be used as the comparable that goes into the dataset.
I need to then add a unique code, which I have available, and add a mapping to the label afterwards.
I have successfully done this with both the legend and tooltips, but I have not found a method where I can convert the code to labels on the DomainAxis.
Can anyone give a clue? Is it possible?
Thanks
Magne
DomainAxis comparable to label
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You don't have to use a String for your category keys. You could write your own class that implements Comparable, has a hidden (and unique) key, but implements the toString() method in a way that two different keys can return the same string. It it the toString() result that is used as the label on the chart.
Of course, you will confuse your users if you have two distinct categories with the exact same label.
Of course, you will confuse your users if you have two distinct categories with the exact same label.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Ah, of course.
It is kind of embarrassing when the solution is so simple as this. I was nowhere near the solution. And I call myself experienced!!!
I agree that the user would find having the same label confusing. It is mostly when using area names it happens. They are unique in the sense that you know the parent region to it, but still the label would be the same. E.g. I have a dataset from the UK where there are several areas/towns called "Old Town" but still they have their own unique (LSOA) code.
I have no guarantee that they will not try to graph the two at the same time.
Separating them would make it confusing, but merging them because the string is equal would be directly wrong.
Well, thanks a lot for this. You simplified my code quite a bit.
Have a nice weekend
Magne
It is kind of embarrassing when the solution is so simple as this. I was nowhere near the solution. And I call myself experienced!!!

I agree that the user would find having the same label confusing. It is mostly when using area names it happens. They are unique in the sense that you know the parent region to it, but still the label would be the same. E.g. I have a dataset from the UK where there are several areas/towns called "Old Town" but still they have their own unique (LSOA) code.
I have no guarantee that they will not try to graph the two at the same time.
Separating them would make it confusing, but merging them because the string is equal would be directly wrong.
Well, thanks a lot for this. You simplified my code quite a bit.
Have a nice weekend
Magne
I have now gotten this to work as I wanted, but not without some trouble.
You said it should be a Comparable, which it must be.
However this only seems to be needed as a signature of the addValue() method. When I add my Comparable class my compareTo() method is never called. The Object.equals() method is instead called to do the test if a item is the same as the other or not. The equals method is not a part of the Comparable interface, but a part of Object. So you might aswell use a Object input for the Dataset.addValue() methods instead of a Comparable.
I do however think that using a Comparable is the correct way of doing it, but you should make use of the compareTo() method and not just the Object.equals method.
There is no error here, just confusing as the Dataset wants a Comparable, but does not make use of its method.
Thanks
Magne
You said it should be a Comparable, which it must be.
However this only seems to be needed as a signature of the addValue() method. When I add my Comparable class my compareTo() method is never called. The Object.equals() method is instead called to do the test if a item is the same as the other or not. The equals method is not a part of the Comparable interface, but a part of Object. So you might aswell use a Object input for the Dataset.addValue() methods instead of a Comparable.
I do however think that using a Comparable is the correct way of doing it, but you should make use of the compareTo() method and not just the Object.equals method.
There is no error here, just confusing as the Dataset wants a Comparable, but does not make use of its method.
Thanks
Magne