How to plot a surface with JFreeChart? - java

I'd like to be able to set a colour of every point (addressed by x&y, where x is a DateTime (of joda-time, actually) and y is a double) on a chart to represent a z=f(x,y) value. Is it possible with JFreeChart?

If I understood your needs correctly I think you want to use an XYPlot with an XYBlockRenderer.
Quoting the docs:
A renderer that represents data from an XYZDataset by drawing a color block at each (x, y) point, where the color is a function of the z-value from the dataset
Check the sample image in the docs for XYBlockRenderer: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/xy/XYBlockRenderer.html

I recommend http://www.jzy3d.org
Here are some example charts: http://www.jzy3d.org/gallery.php
And example code to plot a surface: https://github.com/jzy3d/jzy3d-api/tree/master/jzy3d-tutorials

As far as I remember that's not possible by default. You can set only one color for every plotted series. However, I think it's possible to extend AbstractRenderer and achieve what you need.
Of course there is possibility that I'm mistaking. Dont remember for sure. :P

Related

Scatter plot with Jzy3d

I am using Jsy3d to draw a 3d scatter plot in Java. However, I noticed that the drawing order of the points seems to be based on the order of the given List of Points, not on the distance to the camera. Is there a way to fix this?
You are right, rendering is based on point declaration. Why would you change this?
To change the scatter rendering, simply override Scatter.draw(...)
You may use Camera.getDistance(coord) to get the distance to Camera. This method is already used by BarycenterOrderingStrategy in Graph to order the drawables (but this won't work for your scatter as it is a primitive Drawable).

How can I graph values that are incredibly small in Java?

Basically I am attempting to use JFreeChart right now to graph some values. The only problem is that the values are incredibly minuscule, e.g 7.069781E-13. I believe these values are too small for JFreeChart to display. How can I display these small values visually in Java in a line chart format?
It looks like this currently:
And I want to make it look similar to this:
I found a work around.
I simply multiplied all the values by a factor of 100 so the graph now looks similar to the one in the example. I will include a disclaimer in the legend saying the chart has been multiplied by a factor to clearly see the line chart.
Also consider these alternative:
Invoke setRange(), seen here, to expand the y axis in the area of interest.
Add suitable controls, seen here, to control y zoom.
Advise users how to use the mouse for zoom control, as shown here.

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.

JFreeChart grid base axis

I'm using JFreeChart 1.0.14 in Swing application.
I have chart with multiple Y-Axis and I want to change source Axis for chart grid lines. Now them always base on one axis, even if I hide it.
I know there are few similar questions but they are old and I wonder if solution exists now.
If it doesn't what is the best workaround in this task?
For example:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=27885&sid=c4c609f3809d29a46e3e2bbccfac361e
There is still no way to do it natively unfortunately.
I was suggested to override XYPlot's drawRangeGridLines method, but I decided to go another way: to make it works you only need to change axis order because grid lines always depend on 0th axis (and its dataset). Make sure your axis has 0th index in plot axis collection.
NumberAxis axis = new NumberAxis(name);
plot.setRangeAxis(0, axis);
I think it's easiest way at this moment.

JFreeChart Crosshair on a combined plot

I'm using a combined plot composed of 2 graph which share the same X axis (by sharing, I mean, the timeframe is the same for the two graph). The upper graph is a regular timeseries while the lower chart is a barchart. I would like to display a crosshair on the combined chart as a whole... Right now I can display crosshair only on each graph separately even thought I have specify on the combined plot that I wanted to display the crosshair. To be more explicit, I can't synchronise both crosshair... Any idea on how to achieve that ?
thanks
It would appear to work if you use a shared domain axis, as discussed here and as shown in CrosshairDemo2? In addition, an sscce might help clarify your usage.

Categories

Resources