my dog learned polymorphism*
The moose likes Other Open Source Projects and the fly likes Problem with displaying an histogramm with Cewolf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Problem with displaying an histogramm with Cewolf" Watch "Problem with displaying an histogramm with Cewolf" New topic
Author

Problem with displaying an histogramm with Cewolf

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Hi everyone,

After having tested Cewolf for my graphs, I must say that it's an excellent library which is working great for all my graphs but i am now facing a problem with displaying one of my graph. I am supposed to draw an histogram with:
-on the y axis, the number of non-redundant sequences for a gene --> it's an integer.
-on the x axis, the position in the locus of the gene (taken from a database) --> it's an integer.
-on the top of each bar, the name of the gene corresponding --> it's a string.

Which means in other words that each bar corresponds to a gene with its position in the locus and its number of non-redundant sequences.

So in the 1st step, i just tried to display the histogram without the name of the gene on the top of each bar but some reason, the histogram is displayed empty and the x-axis doesn't show up and i am not to sure why.

There is my code Java (a part of it):



And the jsp file corresponding:



Can anyone tell me why i get an empty histogram with that code?
And also how can i display the name of each genes at the top of their corresponding bar?

Best regards.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
if (string == string2)

String are not compared using the == operator, they're compared using the equals method.

And also how can i display the name of each genes at the top of their corresponding bar?

Check out the BarRendererProcessor postprocessor and its showItemLabels attribute.


Ping & DNS - my free Android networking tools app
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ulf Dittmer wrote:
if (string == string2)

String are not compared using the == operator, they're compared using the equals method.



Actually yes you can, and it's working very well as this is what i used to display multiple tables on my page with displaytag and it worked fine. You can use == or equals for strings, it gives the same result.
I know the problem is not on the way i go through my map but on the way probably i am using cewolf to display an histogram that takes two integers as parameters on the x-axis and y-axis.

Ulf Dittmer wrote:
And also how can i display the name of each genes at the top of their corresponding bar?

Check out the BarRendererProcessor postprocessor and its showItemLabels attribute.


Thank you i am going to check now.

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I changed the "==" to "equals" just in case but same result. The histogram is empty and the x-axis doesn't show up.
What is the best method to set an integer on the x-axis corresponding to s specific integer on the y-axis for displaying an histogram please?
Because on your website, you give an example of an histogram but made with a loop with random numbers which gives an histogram that changes everytime you reload the page. In my case, every parameters from the x-axis corresponds to a specific parameter from the y-axis which means that the histogram must not change every time i reload my program.

Thank you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
You can use == or equals for strings, it gives the same result.

I assure you, you can't. Object equality and string value equality are not the same thing.

Have you made sure that the DefaultCategoryDataset object contains all the values you think it should contain?
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ulf Dittmer wrote:
You can use == or equals for strings, it gives the same result.

I assure you, you can't. Object equality and string value equality are not the same thing.

Have you made sure that the DefaultCategoryDataset object contains all the values you think it should contain?


I have no doubt about what you are saying but on my program, the "==" works perfectly fine i promise you as i checked at the same time with my responsibles to make sure it gives the right results and it's all great. I am pretty sure you can use the "==" to check the equality of 2 strings, this is what we used at univ too, but i am not a specialist so i really don't know why it worked on my case when it shouldn't.

Yes i think it does. I am adding the couple of values in the loop so i don't know why it wouldn't work:


this is what i used in the loop to add values in the DefaultCategoryDataset.
nbSeqDistinctG is an integer.
rs.getString(1) is an integer taken from a database. I think i should cast rs.getString(1) into an integer but when i do that, eclipse doesn't accept it.

It's like i can add only an integer and 2 strings in the DefaultCategoryDataset so i think this is not the right method to use in my case?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
on my program, the "==" works perfectly fine

How would you know that since it doesn't seem to work at all?

Yes i think it does. I am adding the couple of values in the loop so i don't know why it wouldn't work

I already assumed that you thought it would work But I asked whether you have actually made sure that all data values that should be added are, in fact, added, precisely because it seems that they might not. You can print each value that gets added to System.out to make sure.

I think i should cast rs.getString(1) into an integer

You can't cast a string to an integer - Java isn't C. But you can use rs.getInt(1) instead.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ulf Dittmer wrote:
on my program, the "==" works perfectly fine

How would you know that since it doesn't seem to work at all?


I know it's working because like i said upper, i built multiple tables using displaytag library based on those maps which contains all my results and it worked fine. I checked manually all the results with my responsibles and there is no mistake at all. Plus, i changed then the "==" with the "equals" like you proposed but it didn't change the results at all (neither on the tables nor on the histogram which stays empty) All i want is to display the same results that i have on the tables but on a graph which will illustrate the tables.

Ulf Dittmer wrote:
Yes i think it does. I am adding the couple of values in the loop so i don't know why it wouldn't work

I already assumed that you thought it would work But I asked whether you have actually made sure that all data values that should be added are, in fact, added, precisely because it seems that they might not. You can print each value that gets added to System.out to make sure.


Yes and like i said earlier, i used the same loop to build my tables and each values were added, there is no problem with that.

Ulf Dittmer wrote:
I think i should cast rs.getString(1) into an integer

You can't cast a string to an integer - Java isn't C. But you can use rs.getInt(1) instead.


That's what i meant, i have done rs.getInt(1) to get the integer but eclipse doesn't accept it. It shows a mistake at :



saying The method addValue (Number, Comparable, Comparable) is ambigous for the type DefaultCategoryDataset that's why i think it seems impossible to add integers on the x-axis with that method and that's why the x-axis doesn't show up on the histogram ( i have only the y-axis , the title but everything else empty).

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Plus, i changed then the "==" with the "equals" like you proposed but it didn't change the results at all (neither on the tables nor on the histogram which stays empty)

Well, this is at least one of the problems; there may of course be more (and apparently there are).

The method addValue (Number, Comparable, Comparable) is ambigous for the type DefaultCategoryDataset

If you look at the javadocs, you'll see that the ambiguity results from the first parameter, not the third. Try something like "ds.addValue((double)nbSeqDistinctG, "gene", new Integer(rs.getInt(1))"; you may have to experiment a bit. cewolf is from the pre-autoboxing era, so relying on that is tricky.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ulf Dittmer wrote:
Plus, i changed then the "==" with the "equals" like you proposed but it didn't change the results at all (neither on the tables nor on the histogram which stays empty)

Well, this is at least one of the problems; there may of course be more (and apparently there are).

The method addValue (Number, Comparable, Comparable) is ambigous for the type DefaultCategoryDataset

If you look at the javadocs, you'll see that the ambiguity results from the first parameter, not the third. Try something like "ds.addValue((double)nbSeqDistinctG, "gene", new Integer(rs.getInt(1))"; you may have to experiment a bit. cewolf is from the pre-autoboxing era, so relying on that is tricky.


well i tried this but i got the same thing which means an empty histogram.

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I also tried to add some random values but outside the loop and i am still getting nothing so i do think its the way i am building the DefaultCategoryDataset that provocated a problem.
To sum up, i have done :
1. DefaultCategoryDataset ds = new DefaultCategoryDataset();
2. ds.addValue((double)nbSeqDistinctG, "gene", new Integer(rs.getInt(1))
3. return ds

Is there anything else i need to do to have an histogram with that?
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
i found the origin of my problem but i am not sure how to solve it.
I initialize the DefaultCategoryDataset before my loop but i fill it inside my loop and add the return after my loop. So no data is sent and that's why i am getting an empty histogram (cf my code above).
The problem is if i add the DefaultCategoryDataset inside my loop, then the return at the end gives a mistake as the program can't find the DefaultCategoryDataset (as it's inside my loop).
So i am not sure where to put the DefaultCategoryDataset ds and the return ds to make it all right.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Unless I'm missing something, the code looks exactly right with respect the "ds" variable. I think the problem lies elsewhere.

Have you actually counted the number of times the addValue method is called? Is the number what you expected it to be?
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ulf Dittmer wrote:Unless I'm missing something, the code looks exactly right with respect the "ds" variable. I think the problem lies elsewhere.

Have you actually counted the number of times the addValue method is called? Is the number what you expected it to be?


No i didn't count it (i am not sure how?) but what i have done is i used some random real numbers as a test inside my loop that i added to ds and it gave me an empty histogram. But when i have done the same exactly thing but outside my loop, then it gave me the histogram with the random numbers.
In another test, i have tried to print everything inside my loop and like i said, there's no mistake there as everything that i need is printed ( and this is what i used to fill my tables).

So it's like if the ds is not filled inside my loop, no matter what the values are .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
I think you're missing what I'm trying to say. While I'm not sure what you actually tried (I don't understand what you mean by "in the loop" and "outside of the loop"), what I'm saying is: take the actual code -not some other test code-, put an "int count=0;" at the beginning, put a "count++;" right next to the addValue call, and a "System.out.println(""+count)" before the return statement. Then you can see in the log file how many times addValue is called. If that number is correct, then the problem is with the data passed to addValue, but if that number is incorrect, then you need to look for (additional) problems elsewhere.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
when i say loop, i mean this : for (String string : map.keySet()) {.......}

well i found the real problem and why this loop is not working. It's because the method public Object produceDataset(Map params) can't access to the maps i created before in the same class but in another method.

Like i said in my 1st post, my class is very complex. I have different methods:

It allows to add strings to a HashMap


It will allow me to go through the HashMap i took as parameter, and do some calculs inside and then create the tables corresponding to each tables (20 tables)


it parses a text file and add the elements i want in different HashMap that i named before. I call the 2 methods above.

This structure works fine for the tables.
But the method in cewolf can't access the tables i created in the last method.

Do you think i can for example do something like this:



and then call this method where i created the maps for example, a bite like we usually do with displaytag? Otherwise, that means i would have to create 20 classes for all my graphs?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Do you think i can for example do something like this:

and then call this method where i created the maps for example, a bit like we usually do with displaytag?

Your code doesn't call produceDataset - cewolf does that. And you can't change its signature.

Otherwise, that means i would have to create 20 classes for all my graphs?

Only if the charts are fundamentally different. Otherwise, you can send parameters from the chart tag in your JSP to the produceDataset method - that's what the params parameter is all about.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
All the graphs will be bar charts with the same x-axis et y-axis and the name of the gene on each bar but all the values are taken from a different HashMap, that's the only difference. I have 20 HashMap with the same kind of information (gene, locus, number) but different values according to the HashMap.
According to that information, do you think i will have to create 20 classes?
Otherwise, is there any example of how to use this params parameter?

Thank you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
No, you don't have to create 20 classes - 1 is enough. You just need to write the code in produceDataset in a way that it knows which of your data to access. That could be triggered by some parameter you pass in from the JSP. An example of that can be found in the cewolfexample web app - the producerparams.jsp passes 2 parameters to the RandomXYData class.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Thank you for the information. I've just seen the example you gave me. But i can't really see how you can pass a map as parameter and how would you call it in the jsp file.
I know with displaytag, i used to pass my maps as parameters like this:

On the java code:


On the jsp file:


geneV being the ArrayList that contains all the informations i want for example.

Is it the same with Cewolf?


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
No, you would not pass those maps through parameters in the JSP page. You would make pass them to the Java class where you implement the DatasetProducer interface. You could either pass them to the constructor, or add them later via setter methods, or make arrangements so that the produceDataset method can get them some other way. But it would all happen in the Java code. The JSP would merely pass in some parameter that would let the Java code distinguish between those 20 different charts.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
you mean something like this


But then, if you do that, you wont really have control on your charts, right? I mean you won't be able to "print" them wherever you want on the jsp file as the produceDataset is called only once, which means all the charts will be printed all at once?

Is there any example passing maps as parameters so i can see the result please?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
I'm not sure I follow - where they appear on the JSP is controlled by the JSP, not by any Java code.

And no, if you have 20 charts on the JSP, then produceDataset would be called 20 times. Just be sure to pass in the appropriate parameter, so that it can differentiate between the various invocations.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Ok i understand.

Well i fixed the display problem (but without passing the HashMap as parameters, i couldn't do it, it's a bite complicated in my case). I have my histogram but i have one problem. The x-axis is not in the ascending order. Which type of graph do i need to use to have an histogram ordered on the y-axis and the x-axis (as i have integers on the x-axis)?
I used the VerticalBar3D type but i don't think its the appropriate one and the histogram type doesn't work on my case.

You will see an example of what i am getting in the attached file.

Also how do you use the showItemsValue in the chart? In my case, i want to display a "String" (java variable) which is unic and specifc to each bar. I tried to use the series options but this is not good as it gives a not nice output (see the attached file). So this is the series names which appear on the legend on the previous file that i want to display on each bar.

Thank you for any help you can give.

Regards.





[Thumbnail for Screenshot.png]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Which type of graph do i need to use to have an histogram ordered on the y-axis and the x-axis (as i have integers on the x-axis)?

The order along the X axis is the order in which you add values to the dataset. I don't understand what you mean by the order along the y axis.

Also how do you use the showItemsValue in the chart?

Do you mean the showItemLabels attribute? It's a boolean attribute of the BarRendererProcessor; see its javadocs and the StackedVerticalBar example of the "Cewolf Set" page in the example web app.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I mean for example 85000 is before 45000 on the x-axis and i wanted to do something like on the file attached, that is to say . like on the y-axis where the values start from 0 to a certain value. I am not sure if you understand what i mean.

I have seen your example of the StackedVerticalBar but the values are multiple and inside the bars. I just wanted to put one label and at the top of the bar. Is there an example of how to do that?


[Thumbnail for outside-23to26-histogram.jpg]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
I mean for example 85000 is before 45000 on the x-axis and i wanted to do something like on the file attached, that is to say . like on the y-axis where the values start from 0 to a certain value. I am not sure if you understand what i mean.

As I said, the items appear in the order in which you add them to the dataset. If you want 45000 to appear before 85000, then you need to add it before it.

If you want the x values treated as proper numbers, then a category plot isn't the best choice anyway. Try a "verticalxybar" chart type with an XYSeriesCollection dataset.

I have seen your example of the StackedVerticalBar but the values are multiple and inside the bars.

There are multiple values because there are multiple items per category; if there is just one -as in your case- it will be above the top of the bar.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
So i have used the verticalXYbar type but it gave me on the x-axis some times values which is not corresponding to my values. So i used the histogram type which worked perfectly apart that the bar are really thin and i am not sure why. See the attached file please. Can you tell me how to fix it please?
There is my java code:



And my jsp file:



Regards.


[Thumbnail for Screenshot-1.png]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Yeah, I just discovered that verticalXYbar only works with date/time data; I've never worked with that chart type so I've no idea how that came to be. I'm attaching a bug fix version that should allow you to use verticalXYbar charts and get correct X axis values.


[Download cewolf-1.1.3.jar] Download

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Thank you for fixing the bug but i have just tried your new version and it still gives me some date values. See the attached file please.


[Thumbnail for Screenshot-2.png]

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I am sorry i just realized that when i added the new jar, i have forgotten to delete the old jar. So i deleted it, and it worked fine now. I have normal values on the x-axis but the bars are still very thin like with the histogram type. Is there any reason you see why this is happening? Is it a problem in the method public String getProducerId() ? What should i return here now ?



[Thumbnail for Screenshot-3.png]

michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Also about the labels, i have seen that you used in your example series with a start value and an end value. But how do you add series to a verticalXYbar please?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Like this:
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
Thank you but this is not what i meant. I have already done this to add the couples (x,y) to build my chart that i showed you (see above). But my question was how to add series names (which are not x or y) like in the verticalBar so that i can add those series as labels in the top of my bars a bite like you have done here:



This code is for the vertical Bar where you have categories and series. Is it possible to have those series as well with the verticalXYBar (knowing you don't have any categories with this type)?

PS: sorry to insist but have you got an idea why i get very thin bars on the chart above please?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Those labels are a feature of category plots; they're not available on XY plots.

You can simulate them by writing a postprocessor that adds XYAnnotation objects at each data point. See the de.laures.cewolf.cpp.AnnotationProcessor class for the details on how to do that.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
ah ok thank you i am going to check it that.

and about the bars size on my chart, is there anything i can do to fix it?
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I solved the size problem thanks.

I am working now on the labels part on XY plots but it seems very hard as the labels i need to add on the bars are from a HashMap and they are dynamic as you can see on the code below whereas your example is static. So according to you, how can i get the variable i need from my java code to be called on the annotation part of the jsp?


Thank you for all the help.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I wanted to know, is it possible to get the zoom function for the verticalXYbar charts? Because i just followed your example on your website and tried to applicate it to my code but it gave me this error:

"java.lang.IllegalArgumentException raised by post processor 'de.laures.cewolf.cpp.ZoomBothAxis@156e1ed'. Post processing of this post processor has been ignored."

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
I've never tried that postprocessor with anything other than that example page, but it can handle XYPlots (which is what verticalXYbar charts use), so my guess is it should work.
michael stoker
Ranch Hand

Joined: Jul 15, 2010
Posts: 39
I modified your code for the verticalXYbar zoom and its working great!
Just working now on the annotations part. That's all i need to finish my graphs.
Do you think if i use something like request.setAttribute on my java code and call it on the jsp file will work?
 
GeeCON Prague 2014
 
subject: Problem with displaying an histogramm with Cewolf