graphs in javaFX? - java

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 every time 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 values from 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..
Scenario
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.

You must have used the following site to go through the documentation on BARCHART IN JAVAFX
http://docs.oracle.com/javafx/2/charts/bar-chart.htm
Over here, when we are filling series1, using series1.getData().add(), instead of passing hardcoded values, you can pass the values that you have fetched from the database.
You can do the same thing for series2, series3.. As many series as you want to make ! Hope things are clear for you, or feel free to comment ! :)
-AA

Related

Anylogic using state charts to travel

I am very new to Anylogic, and I want to model this process that doesn't seem too difficult. However, I really have no idea as to how to go about it. I also do not have a background in Java, so the coding bit is new to me as well.
I have the following state chart within an agent called a "picker":
I have a list of items in a warehouse in an excel sheet the columns are "Items, x-coordinate, y-coordinate" which is already in the model (roughly 10 rows). I want to pull the x-coordinates and y-coordinates from all the items listed in that excel file in the "getList" state. Next I want the "picker" to travel to each of those locations one-by-one until every item has been picked. The branch is asking "Do you have all the items?" If yes, it will continue to the "done" state.
Thank you in advance!

Dynamic amount of entries in GUI using java

I'm working on creating a basic user interface and I wanted to try and create a portion that is in a scrollTaskPane and is capable of holding multiple entries. As I'm going about creating it I can obviously test it with a simple amount of entries but I'm confused how I can go about later allowing for it to take input to create entries in the scrollTaskPane of maybe 1 entry one time, and then later needing to allow for input of 20 entries. I only know how to use absolute positioning and am trying to figure out the best way to go about it. I also need to later be able to select each entry.
For the entries that will eventually be called and displayed in my interface, I'm planning to store them in a simple text file and use a semicolon as a delimiter between the task "Type" "Name" "Description"(which will be accessible through a button) and "Due Date". Or I may try to learn to use a database for the information. But I haven't decided yet and don't know anything about connecting a database with a java program.
This is the current look (the scrollTaskPane in the middle). And my goal is to put in entries that are each rectangle boxes going across the scrollTaskPane with a checkbox on the end of them. Should I use some sort of grid layout? Or something else? I'm a beginner at user interfaces, so any help is appreciated!
You can make a custom layout, and then keep adding those layout. So extend a layout class, add TextField and a check box in the layout. Initialize the layout with your values, add then add to the ScrollTaskPane.

How to get the top 10 value in BIRT

I have a trouble that I need to get the top 10 busiest stations, right now, I have these columns (number of buses, datetime, station name). Now, I can dynamically change the time range based on user's selection. But, the BIRT just show all the stations' name in one chart. How can I get the top 10 stations' name? I tried to add filter in my chart, but after I added it, it only showed one station name. Can anyone help me solve my problem? (In my chart, the X-axis is the station name, and Y-axis is the number of buses)
This is probably because stations data are aggregated on-the-fly in the chart view, whereas the top 10 filter you added is filtering on details rows before aggregation. As far as i know we can't specify that a chart filter should be applied at a group level such as we can do it with a table element.
Therefore you should aggregate data before rendering the chart. There are a couple of ways to do this:
Aggregate data in your dataset (SQL group by, ...)
Aggregate in a hidden birt table element with groups, and base the chart on this table. Notice in this case the top 10 filter has to be defined in the table element
Aggregate using a datacube, and base the chart on this datacube or a crosstab
If you cant't make it work as expected, for this kind of issue you should post a .rptdesign based on "Classic models" database sample.

Best way to implement a selection box from a large number of entries

I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array

Help with Java program (Swing + database)

Could somebody give me a suggestion on how to simply and effectively make GUI representation of directories which are contained inside the database. Now, getting information using SQL queries is one thing. I can do that.
In fact using separate small examples I can put a file inside the database along with his information and I can get the file out of the database. The thing is I was just doing this without GUI, just to test does it work.
Now I need a GUI of this and I really don't know where to start. DO I use JTable, JList or something third? Also, I think I need an multidimensional array because I have, for example, id of a file, name_of_file and size.
So I need different types to put them in: int, String and int.
Also, I need to obviously hide the id of a file from the user yet keep it at the same time in order to be able to reference it.
How do I hide it in a GUI component?
So, let's say that I have a database table for files with these columns:
id, name, size, binary_of_file.
My real table has a bit more of columns like, id of a parent directory, id of a owner, etc. but for now this is not important.
So, I tell database to give me all info about the file (except it's binary because I just want to list the files):
...
ResultSet rs = statementObject.executeQuery("SELECT id, name, size FROM Files;");
while(rs.next()){
//Where do I store the values in? Which GUI component and how?
...
I guess I need an JPanel that will contain this component that will show my files from the database. What component? Please help!
It sounds like you want to use a JTable, it has a TableModel interface that you can implement to adapt to your resultset.
Also follow the link at the top of the docs. to Creating a Table Model.
Perhaps a combined JList/JTable component would fit this need.
That is a screen shot of the GUI of FileBro.
My idea is that the JTree on the left would represent the 'directories' and table (names) of the DB. The JTable on the right would contain the data of the selected table. Change the Locate Open Edit Print buttons for Create Update Delete and the panel below that to show details of records, and it would be the start of a DB CRUD component.

Categories