Array in XYLineChart with Own ToolTip
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
Array in XYLineChart with Own ToolTip
Hello,
i am new to JFreeChart, i already tested some examples of it (PieChart and XYLineChart).
these examples works very good and includes also the standard Tooltip (it means: it shows the Dataname, xvalue and yValue in the Tooltip).
My question is:
I have an 2 dim. Array with 4 columns ( x | y | d1 | d2 )
my XYLineChart has the x as xvalue and y as yvalue.
The Tooltip of each point musst contain the x, y Values and the d1 and d2 Values (better x any in a line and d1 and d2 in a new line in the same toolTip. Like this:
Data -> chartName
123 , 345 -> x , y
0.1 , 0.31 -> d1, d2
).
Can someone tell me how can i do it? and if you have an example for me, i would be Thankful.
i am new to JFreeChart, i already tested some examples of it (PieChart and XYLineChart).
these examples works very good and includes also the standard Tooltip (it means: it shows the Dataname, xvalue and yValue in the Tooltip).
My question is:
I have an 2 dim. Array with 4 columns ( x | y | d1 | d2 )
my XYLineChart has the x as xvalue and y as yvalue.
The Tooltip of each point musst contain the x, y Values and the d1 and d2 Values (better x any in a line and d1 and d2 in a new line in the same toolTip. Like this:
Data -> chartName
123 , 345 -> x , y
0.1 , 0.31 -> d1, d2
).
Can someone tell me how can i do it? and if you have an example for me, i would be Thankful.
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Create a class that implements the XYToolTipGenerator interface. StandardXYToolTipGenerator is an example you should look at, and you already know how to use it. You might want to consider creating a class that implements the XYDataset interface to specifically handle your data.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
thanks
Thanks Richard for your Help.
I looked at the StandardXYToolTipGenerator class. the class implements the interface XYToolTipGenerator and oder interfaces. i should use the method generateToolTip(XYDataset dataset, int series, int item) But i dont know how.
If you or someone else can give me an example here or in the internet, that would be grateful.
Thanks again
I looked at the StandardXYToolTipGenerator class. the class implements the interface XYToolTipGenerator and oder interfaces. i should use the method generateToolTip(XYDataset dataset, int series, int item) But i dont know how.
If you or someone else can give me an example here or in the internet, that would be grateful.
Thanks again
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: thanks
It really depends upon how you are storing and retrieving your data. Creating your own XYDataset-based class would allow you greater control over the data. All you would need to do is provide additional accessors in your class to return d1 and d2 based upon which item in which series is requesting the tooltip.s2tsefanie wrote:If you or someone else can give me an example here or in the internet, that would be grateful.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
own Tooltip doesnt work 100%
Hello again.
THanks Richardwest for your help.
I programmed my own tooltip and worked. It was a constant tooltip (constant string)
I have now an other similar Challenge, and always with Tooltip. now I have the folowing exercise:
have an 2 dim. Array with 3 columns ( x | y | d )
my XYLineChart has the x as xvalue and y as yvalue.
the XYLinechart works well. I want that the tooltip for each point x,y to be d.
I tried the search in the 2dimensional Array, but it doesnt work. it take a long time to search, and doesnt find anythikg an the ende.
does any one knows where the problem is?
Thanks for your help
THanks Richardwest for your help.
I programmed my own tooltip and worked. It was a constant tooltip (constant string)
I have now an other similar Challenge, and always with Tooltip. now I have the folowing exercise:
have an 2 dim. Array with 3 columns ( x | y | d )
my XYLineChart has the x as xvalue and y as yvalue.
the XYLinechart works well. I want that the tooltip for each point x,y to be d.
I tried the search in the 2dimensional Array, but it doesnt work. it take a long time to search, and doesnt find anythikg an the ende.
does any one knows where the problem is?
Thanks for your help
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: own Tooltip doesnt work 100%
Your description is slightly vague and hard to follow. If you have been able to create custom tooltips using your (x, y, d1, d2) ordinal-quad array, you should be able to apply the same techniques to a (x, y, d1) ordinal-triple array. If you are not getting a value after searching the array, either the value you are searching for does not exist or your search logic is wrong. It strikes me as odd that you would be searching for values when you should be able to simply access them by index. Although, I could be completely misunderstanding what you are trying to do.s2tsefanie wrote:does any one knows where the problem is?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
(maybe) its not easy as you said
n the first example i used a Contant string witch i display as a tooltip. it has nothing to do with the values x and y. I just wanted to tell you that i found where to manipulate the tooltips.
By the second Exercise: the Tooltip depends on the Point (x,y).
here is the Code for the tooltip class:
I hope now you understand what i mean. and hope you can help me.
Thanks anyway
By the second Exercise: the Tooltip depends on the Point (x,y).
here is the Code for the tooltip class:
Code: Select all
class myToolTip extends AbstractXYItemLabelGenerator implements XYToolTipGenerator{
private static final long serialVersionUID = 1L;
//generateToolTip : XYToolTipGenerator
public String generateToolTip(XYDataset dataset, int series, int item) {
return generateLabelString(dataset, series, item);
}
//generateLabelString : AbstractXYItemLabelGenerator
public String generateLabelString(XYDataset dataset, int series, int item) {
String result = "";
// Object[] items = createItemArray(dataset, series, item);
Object[] items = {dataset.getSeriesKey(series).toString(),//Name
dataset.getXValue(series,item),//xValue
dataset.getYValue(series, item)};//yValue
//the method getName takes the x and y value und should get the d Value
result = getName(items[1],items[2]);
return result;
}
private String getName(Object a, Object b){
String er="";
// String sx=a.toString(), sy=b.toString();
for (int i = 0; i <csvValues.length ; i++) {
//csvValues is the Array where are stored the Values d|x|y
if(a.equals(csvValues[i][1]) && b.equals(csvValues[i][2]) ){
//when the items 1 and 2 equals the x and y Values
er += csvValues[i][0].toString();
//er gets the d vales
//System.out.println(er);
break;
}
}
return erg;
}
}
Thanks anyway
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Your approach seems overly complicated. As I sugested before, you should create your own dataset. It would make handling the data much simpler and it would simplify your custom tooltips as well.
Here is a quick, dirty, and untested example:
Read the JavaDocs for more information about the classes and interfaces referenced in the above code. I have simply made a dataset with only one series whose data is supplied in an array of (x, y, d) ordinal-triples. You will have to play around if you want to handle more than one series. However, it should be apparent that this is a much more elegant approach to this problem that your complicated lookup logic.
Here is a quick, dirty, and untested example:
Code: Select all
public class CustomDataset
extends AbstractXYDataset
implements XYDataset
{
private double[][] m_data; // x, y, d
public CustomDataset (double[][] x_data)
{
super();
m_data = x_data;
}
public DomainOrder getDomainOrder ()
{
return DomainOrder.ASCENDING;
}
public double getDValue (int x_series, int x_item)
{
return m_data[x_item][2];
}
public int getItemCount ()
{
return m_data.length;
}
public int getSeriesCount ()
{
return 1;
}
public Comparable getSeriesKey (int x_series)
{
return "blah";
}
public Number getX (int x_series, int x_item)
{
return new Double(getXValue(x_series, x_item));
}
public double getXValue (int x_series, x_item)
{
return m_data[x_item][0];
}
public Number getY (int x_series, int x_item)
{
return new Double(getYValue(x_series, x_item));
}
public double getYValue (int x_series, int x_item)
{
return m_data[x_item][1];
}
}
public class CustomToolTips
implements XYToolTipGenerator
{
public CustomToolTips ()
{
}
String generateToolTip (XYDataset x_dataset, int x_series, int x_item)
{
CustomDataset l_dataset = (CustomDataset)x_dataset;
StringBuilder l_tooltip = new StringBuilder("(");
l_tooltip.append(l_dataset.getXValue(x_series, x_item));
l_tooltip.append(", ");
l_tooltip.append(l_dataset.getYValue(x_series, x_item));
l_tooltip.append(") d = ");
l_tooltip.append(l_dataset.getDValue(x_series, x_item));
return l_tooltip.toString();
}
}
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
java.lang.ClassCastException
Hi,
thank you for your help.
i did you do, and tested ma code with my own dataset, it works with the drawing of the data, but not with the tolltips.
i get the error java.lang.ClassCastException at the line
from the Tooltipgenerator Method.
do you know how can i fixe it?
Thanks
thank you for your help.
i did you do, and tested ma code with my own dataset, it works with the drawing of the data, but not with the tolltips.
i get the error java.lang.ClassCastException at the line
Code: Select all
myDataset l_dataset = (myDataset)x_dataset;
do you know how can i fixe it?
Thanks
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
the full exception
sorry, hier is the Exception with the message:
Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jfree.data.xy.XYSeriesCollection
at myDatasetTest$myToolTips.generateToolTip(myDatasetTest.java:703
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: java.lang.ClassCastException
It is hard to tell without greater context. As I stated above, the code was supposed to be a quick and dirty example and not a full solution. I was leaving the kinks to be worked out by yourself as you adapted the example to fully meet your needs.s2tsefanie wrote:do you know how can i fixe it?
I am suprised to see a class cast exception involving an XYSeriesCollection. The file name and line number mean nothing without seeing the file. If myDatasetTest.java is a standalone application, post the code in code tags for me to take a look at.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 8
- Joined: Mon May 26, 2008 9:46 pm
an other Problem
Hi,
once again its me.
thank you all for your help.
and once again, i have problems with my Tooltip:
The example you give me RichardWest worked, I didnt do anything special, i only tested it many times and it works.
My Problem now is: the tooltip isnt 100% correct: it shows false tooltips for a point (i mean, for a point p, it shows false x, y and d Values).
what did i do wrong? or where is the problem?
Thanks in advance
once again its me.
thank you all for your help.
and once again, i have problems with my Tooltip:
The example you give me RichardWest worked, I didnt do anything special, i only tested it many times and it works.
My Problem now is: the tooltip isnt 100% correct: it shows false tooltips for a point (i mean, for a point p, it shows false x, y and d Values).
what did i do wrong? or where is the problem?
Thanks in advance
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: an other Problem
Again, it is hard to tell without greater context. We need to know what you are doing and how you are doing it before we can tell you what you are doing wrong. Without this, we cannot help you.s2tsefanie wrote:My Problem now is: the tooltip isnt 100% correct: it shows false tooltips for a point (i mean, for a point p, it shows false x, y and d Values).
what did i do wrong? or where is the problem?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA