I have a JFreechart, showing stocks data, the type of dataset i use to plot it is an OHLCDataset.
I can get the actual X value from the point where the user click on the plot (i mean, i get the real date corresponding to that point, not just the coordinate on the window).
Next step i need to make is get the data from the OHLCDataset corresponding to that date, to be able to get the Open.High,Close and Low values in that date, but i just can find ways to get the OHLCDataset date corresponding to an item (an integer wich indicates the ordinal), not even one way to obtain that item having the date.
¿Any ideas of how to get the item having the date?
Thanks.
The approach suggested is tedious and error-prone. Instead, add a ChartMouseListener, as shown here. You can invoke getDataset() on any XYItemEntity you encounter.
Related
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
I am trying to make a program to do calculations of doubling time based on multiple readings at different points in time.
I am using a Netbeans JFrame with a JTextfield and a DateChooser with an add button. I intend to add the values in the JTextfield and the DateChooser to a two dimensional array of the data type [Date,double] each time the add button is clicked.
Once all the data is entered I have another button that then plots a graph based on these data points and calculates the doubling time and generates a report.
I am facing the following problems.
I will not know the number of elements I will have it can be 2 it can be 20 it will depend on the observations, I am unsure of how I can set this up in the context of a JTextField, JButton and DateChooser
Any help will be appreciated.
I will not know the number of elements I will have it can be 2 it can
be 20 it will depend on the observations, I am unsure of how I can set
this up in the context of a JTextField, JButton and DateChooser
I wouldn't. It would be eaiser to manage with a JTable.
This way you won't need to care how many observations need to be made, they can simply keep adding new rows as they want.
I would also make a simple Object that contains the Date and double value, maybe called Observation, which can then simply be managed by the JTable's model and if required, transferred to something like a List or array.
This links the Date and value together in a obvious manner which is not easily disconnected - IMHO
Instead of using an Array, use a List. That way you can use List.add() and you don't need to worry about how many elements are going to be in that list.
Elements in a list can be access similar to an array by using List.get(index) to get the objects or a more generic for( element : List ) {}.
You can have complex user type object with 2 fields and then have array of that object.
I'm using the StarTeam java API (v10.4).
I am having a heckuva time trying to find which specific revisions a Label is applied to. What makes this tricky is that there seems to be no method on the Label object which provides a list of what that label is applied to.
So you (seemingly) need to go backwards and find a list of items that you want to check for a particular Label, e.g.
int[] check_these_items = new int[]{ item_to_check.getID() };
int[] labelledItems = myLabel.getLabeledItemIDs(check_these_items)
First, that's kind of convoluted because you need to have a Label in the first place when really what I wanted was to get a list of labels attached to a single revision. But ok, let's go with that for now. So now I need to find a single revision from the history. Let's make this simple and say I want to get the third (or fourth) revision:
Item specific_child = item_to_check.getHistory()[3];
Now the problem is that this new child from history has the same ID (via getID()) as the parent so using getLabeledItemIds(check_these_items) will return the same labels and essentially, we haven't gotten anywhere.
I did find a question related to finding past revisions but it wasn't pertaining to finding labels on past revisions.
Of course, I checked Borland's API documentation but have not come up with the solution.
I know the UI can do it so certainly there is way, I'm just having a time finding it.
Any suggestions even at a high-level would be greatly appreciated!
Once you have the Item and the Label at hand, use getFromHistoryByLabelID(int)
to "Returns the specified version of this item based on the given label ID"
This still doesn't seem like the right answer, but eventually I had to move on and ended up using a workaround of finding the revision date/time of the label I wanted and then comparing the item revision to that. So by that type of reverse logic, I was able to check each label attached to the element and find which revisions had that label.
I've got a DateTime (SWT.TIME) and want to know if the hours or minutes or seconds are selected.
I would like to get this information because I want that the User can scroll the mouse wheel in order to change the selected values accordingly.
Unfortunately I couldn't find any way to get the selected element of the DateTime Control. Does anybody have an idea?
DateTime provides many methods for getting the selected date. Like getHours, getMinutes, getDay, and so on. It's unclear to me what's your exact question, but appropiate setters are there as well.
I want to implement a date chooser using a JSlider. The user should be able to use the slider to freely choose between two previously known dates. I've seen examples like this one:
But I want to do the same, using only one slider. The minimal distance between two points (tick) should be one day. Any hints how to implement that?
If you want to have a slider with min = 1.1.2012 and max = 10.1.2012 just create a slider with min = 0 and max = number of days in between, then add the selected number to 1.1.2012.
I assume 10.1.2012 means January 10th, thus your slider would have min = 0 and max = 9. Then set the labels accordingly.
I can't to image how to do that with one JSlider, because there you'd have bunch of days, there are some workarounds for Double/RangeSlider, but I think better and easiest would be implements JSpinner with SpinnerDateModel, or best options is look for Custom Java Calendar or DatePicker
EDIT (#Robin)
First to answer your question: you can just use a JSlider, use the number of days between your start and end date to determine the range, and use custom labels (by using for example the setLabelTable method)
Now for user-friendliness, avoid this since
Nobody is familiar with this concept. Every site/application nowadays uses a textfield, most of the time in combination with a calendar widget. That is what users expect, not a slider
It will be hard to get all dates as labels on the slider due to the limited width. This means that a user have to interpolate / count to select his correct date
If you stick to the slider approach, at least consider to add a textfield as well. Even a non-editable text field which shows the currently selected date would be a huge improvement over a slider (see point 2)