Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

graphs and charts in javaFX

 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!! is anyone familiar with the graphs and charts availability in javaFX.
i know how to create a bar graph but i have some doubts..
i'm creating a bar graph with the tutorial provided by Oracle but it is taking the values on y-axis that are provided in the program itself..so everytime you run it ,it'll display a graph with the same set of values..
But what i want is the graph should be able to read the vaues form a table in Ms access and then display the graph according to the values from table ,so that every time i run it it'll be showing the values currently in the database..
Is it possible?
Please let me know if there's a way of achieving this.There must be a way else what's the point of having these graphs and charts in javaFX if they're only going to take static values..
Please let me know..
Thanks..
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is http://docs.oracle.com/javafx/2/charts/bar-chart.htm what you're trying to do? It would seem easy to replace the numbers in the code by whatever dynamic numbers you want to display. What particular difficulty did you encounter when trying to do that?
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i used the same tutorial..ohk .
I have a table in ms access with 2 columns "blood group" and "no.of units".
see now the no of units in a blood bank keeps varying when a patient reuires some units of a blood group or when a hospital adds up units to it's blood bank.
so what i want is that graph should be able to read the "no.of units " from the table and display the level of each blood group accordingly.so even when the column "no of units" gets modified due to certain operation when i click on a button it should be able to display the graph with the current values of each blood group from the table..
Now can you tell how should i do it ??
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you are able to create a chart with your own data, but now you want to update the data and have that reflected in the chart.

My guess would be that you'd remove and add data series from the ObservableList you obtain by calling getData() on the chart.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what ObservableList is? can you just write a statement how to achieve it.
i know this much : i'll create a JDBC connection execute a query preparedStatement ps=con.prepare("select * from <table_name>")
ResultSet rs=ps.executeQuery();
while(rs.next)
{
}
// since "no of units " is the second column in table i can retrieve that value with rs.getInt(2);
now tell me what should i do in while loop so that i can add to the graph the values read from the table.
Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the javadocs of the XYChart.getData() method - it returns a list of all data series in that chart.

You'd get the updated data from the DB in the same manner as the original data. I thought you had that in place already? If not, the example code shows how to add data points to a series individually - you just need to use that in the loop handling the ResultSet.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!1 still there's a problem

table has 2 columns "blood group" and "units" with 6 rows(a,a+,b,b+,o,o+)
Now what should i write to retrieve these values individually from the table.
Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess something like rs.getString("units") or rs.getInt("units").

Also, I advise to migrate away from the JDBC/ODBC driver, which is obsolete and won't be part of Java 8.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, you said "blood group" is a column. Then you would have a single row for each group, no? So you should only be adding a single data point in each iteration through your loop, precisely for the blood group that row deals with.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..i succeded .got the problem..
changes made::
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:Hospital");
PreparedStatement st=con.prepareStatement("select * from blood ");
ResultSet rs= st.executeQuery();
while(rs.next())
{

series1.getData().add(new XYChart.Data(rs.getString(1),rs.getInt(2) ));

}
}
now rs.getString(1)-will feth the String(a,a+ etc)
and rs.getStrin(2)-will fetch corresponding units..
Thanks.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh ohk..but can you suggest what should i use for connectivity..I mean i couldn't use Oracle ,i'm using XP and after sometimes oracle gets corrupt and uses up all my space .there was a file called "log" in one of the folders it got corrupted and it's size got 3 gb.and evry time i used to free up some space from my drive say 700bm then "log" will become 3.7 gb..so i had to remove oracle..
Then i installed ORACLE EXPRESS EDITION ,it worked finr but haven't used it for a while.
So can you tell how to connect with it ..or any other alternative which might be good.
Thanks
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I strongly advise to get into the habit of using column names instead of column indices, though: "rs.getString("bloodGroup"), rs.getInt("units")" instead of "rs.getString(1), rs.getInt(2)", especially if you do a "SELECT *" - which does not guarantee the order in which columns are returned. Or at least do a "SELECT bloodGroup, units from blood" - where the order of columns is guaranteed.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohk thanks..will make sure of that..
and reply to my previous post..about database connectivity.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the first thing about Oracle, except that I would consider it stable and solid. If you're having problems with your installation, start a new topic in the Oracle or JDBC forums.

But if you use Oracle (or any other serious DB) you should use its JDBC drivers, never the JDBC/ODBC bridge. Searching for "download oracle jdbc drivers" should find those fast, and the documentation shows how to use them.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since i have Oracle express edition 10g ,i googled how to connect to it using JDBC .
http://srikanthtechnologies.com/articles/oracle/java.html
they specify 2 drivers
1) OCI (native api)
2) Thin driver
which one should i download?
What are you using ?
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thin driver. But as I said before, if you have DB questions, start a new thread in the JDBC forum. This forum is about JavaFX, where DB discussions have no place.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohkk thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic