dynamically change Y axis range in Jfreechart - java

I have a time series data which I can draw using jfreechart. the issue is, as new data comes in, the chart will change based on the new dataset. I used,
chart.fireChartChanged();
chartPanel.repaint();
the issue is, some data may be out of the current range of Y axis, I'm wondering how can the axis range be changed according to the maximum value in the timeseries I had so far? thanks!

I used chart.fireChartChanged(); chartPanel.repaint();… but the chart still has the old range after repaint.
This all seems unnecessarily complicated: axis ranging and notification should be automatic. In this example, the range changes as outliers accumulate, because add() "sends a SeriesChangeEvent to all registered listeners." In this example, the range is fixed, but the same notification happens.
As we can't guess how your program fails in this regard, it may help to provide an sscce that exhibits the problem(s) you describe.

Have a look at Range class .
There are many methods like
combine(Range range1, Range range2)
Creates a new range by combining two existing ranges.
expandToInclude(Range range, double value)
Returns a range that includes all the values in the specified range AND the specified value.
shift(Range base, double delta, boolean allowZeroCrossing)
Shifts the range by the specified amount.
You can use any depending upon your requirements
you might even have to add following [based on your comments]
timeaxis.setAutoRange(true);
timeaxis.setFixedAutoRange(1000.0);

Related

Bar Graph in jFreeChart w bars all start from a specific range

Is it possible to generate a bar graph in jFreeChart where bars all start around a particular value instead of the zero axis? Our team has interest in this view.
Here is an example where the default behavior has the bars all between the value and the origin. We want the bars to be between the value and the mean (average).
I suppose a workaround is we calculate the offset from the mean and plot them in respect to the origin and then hide the axis but then we are not able to show the axis to our users.
Instead of having bar graphs stop at another value besides the origin we are just redefining the graph axis origin to be at the mean and offsetting everything. So instead of something like exposure level we now call the value axis distance from aggregate mean. Not exactly what I was originally looking in the OP but a cleaner solution overall. We'll let the user toggle between the two modes.

How do you draw smooth curves given integer amplitude points?

I'm trying to draw a sinus wave-form (think Siri) that picks up and is immediately influenced by a user's voice. If I could accomplish exactly this in Android with as much fluidity on a device such as the S4, I will be extremely satisfied, so any helpful information is greatly appreciated.
Right now, I understand how to use the MediaRecorder to grab the max amplitude at a "tick" (reference), and I can store several of these integer values in an array as the MediaRecorder is recording and picking up audio, but I have no idea how I can transform this array of integers into something like the Github project that I posted above. I'd also appreciate if someone could suggest how large this array should be, since I want to dump old data as quickly as possible to make the animation fast and use as little memory as possible.
EMy aproach would be as follows: You could store, say, the last 5 values (In your example, it shows about 5-6 lines at a time).
Then, for each value in these 5 values:
Take the max amplitude value you can get for reference, and use it for calculate a percentage of the current value. Use that percentage along with the sin(x)Math.sin function to smooth the curvy line:
example:
MAX_AMPL:1200
CURR_VALUE: 240 -->20% of MAX_AMPL
Use android drawing primitives Drwaing on android to draw f(x)=(CURR_VALUE/MAX_VALUE) Math.Sin (x)
If you draw the function between 0 and 2Pi i think you will get the same number of waves as in your example.
The more recent the value (position in value ArrayList), the more wider the line for vanishing efect.
Last, draw your graphs from the oldest to the newer.

Why is Sheet.setColumnWidth not in Points? Is there a workaround?

I'm curious why there is no implementation for Sheet.setColumnWidth that accepts a Points parameter.
There is a method to set the height of a Row in points, which is setHeightInPoints
The only available method to set the width is accepting a rather weird scale, defined as
width = Truncate([{Number of Visible Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
This means it depends on some width of a digit, so the value used in the parameter is
just 1/256 of what is wanted here, some straight representation of a width. In Excel itself
you set the width in Points, too.
This means behaviour of Row-height and Column-width is not symetric.
Is there any rational reason for only having that version of setColumnWidth?
This leads to serious problems, as the best I can get has a different result on every computer,
because the width which is set is depending on the users default font setting.
I believe it has something to do with displaying nicely on many different setups, as the comment of pnuts suggests. But it is only usable in a very narrow field.
At the moment I believe that there is no simple workaround for that, and I cannot find one right now. (just one that works for my case perhaps)
Is there any good way to calculate a column width value from a desired points value?
I.e. I want 120 points on any computer that is using the excel export functionality. What is the width value to use as parameter here to get the wanted points width?

Scale factor of a function plotter

I have done my own function plotter with java which works quite well.
All you have to do is to iterate over the with (pixels) of the panel and calculate the y-value. Then plot it with a poly-line onto the screen and that's it.
But here comes my problem: There is a scale factor between the number of pixels and the value which I want to plot.
For example I'm at the 304' iteration (iterating over the with value of the plot panel). Now I calculate the corresponding value for this pixel position (304) by the rule of three. This gives me 1.45436. Then I calculate the sin based on this value. Which is transcendetal number. Then I use again the rule of tree to determine which y-pixel this value corresponds to. Doing so, I have to round because the pixel is an integer. And there is my data loss. This data loss may give me the following result:
This looks not really nice. If I play around with resizing the window I sometimes get a smooth result.
How can I fix this problem? I've actually never seen such plots in any other function plotter.
If you do this in Java, you might consider composing your data points to a Path2D. That would have floating point coordinates, and the drawing engine would take care of smoothing things down. You might have to disable stroke control, though.

Java3d. How to increase range of sight?

If I create a simple application where I can fly over a plain I can only see a little of the plain. The engine only renders in a certain radius around the camera. Everything that's beyond appears in the background colour. So it feels like being in a fog where my range of sight is only a couple of meters.
How do I increase that range of sight?
javax.media.j3d.View.setFrontClipDistance(double distance)
More data found here:
http://download.java.net/media/java3d/javadoc/1.3.2/javax/media/j3d/View.html
Sorry if this seems a bit late but I want to clarify for future reference the best answer is not exactly correct.
setFrontClipDistance Is the point that something un-renders as you get close to it, by default
this value is .01(meters) as you do not want something to un-render when you are 10 meters from it, well at least in most cases.
What is truly being asked is the how to increase the Maximum render distance and that is done with setBackClipDistance, default set to 10(meters). If you set it to 1000 then that would increase the maximum render distance to 1000 scale meters.
The proper way to set this, assuming you are using a simpleUnivers object, is to access the function in the View of the instanced object.
//Create a Simple Universe object using a 3d canvas object you have
SimpleUniverse simpleU = new SimpleUniverse(Your3dCanvasHere);
//add in your compiled branch group
simpleU.addBranchGraph(YourBranchGroupHere);
//Increase the render distance with setBackClipDistance
simpleU.getViewer().getView().setBackClipDistance(1000);
If you are planning to develop something serious, you shouldn't stick to Java-3D. Try to use OpenGL. OpenGL comes with a function:
gluPerspective(fieldOfViewY, aspect, near, far);
The far parameter is what you are looking for. OpenGL is way more efficient than a CPU based drawing engine, because it uses the GPU.

Categories

Resources