Can one detect when a JFreeChart ChartPanel has changed its zoom? - java

In a JFreeChart application, is it possible for the application to detect when its ChartPanel object has changed its zoom state, i.e., it has either been zoomed in or zoomed out? Is it possible to install a listener that will detect such a zoom state change?
For the record, I'm using the JFreeChart-FSE ("future state edition") library, so if there is no way to do this in the regular library, can it be done in FSE?

You could try to add a listener to the Plot of your ChartPanel.
The plot has the method addChangeListener().
So, when your plot is loaded, your compute the original zoom state.
You could associate the zoom state to visible data in your plot.
For example, the zoom state on domain Axis could be computed from the actual lowerBound and upperBound values like that :
double lowerBound = yourChartPanel.getXYPlot().getDomainAxis().getLowerBound();
double upperBound = yourChartPanel.getXYPlot().getDomainAxis().getUpperBound();
When your listener is called, you just have to check if the zoom state has changed since the last time.

Related

JAVA Google Maps API : set boundaries depending on zoom value

I'm trying to update the camera boundaries every time the zoom value changes. After checking the doc, I found that it's possible to extend the current boundaries by using method LatLngBounds Including(LatLng point) which return the smallest LatLngBounds that contains the LatLng point. So I made this code :
// I save the initial zoom value and I test if it changes
double zoom = mMap.getCameraPosition().zoom;
if (zoom!= mMap.getCameraPosition().zoom){
// I create a new Bounds which is proportional to the difference of the previous and the new zoom value by including a new point in the boundaries
LatLng chgtBounds = new LatLng(ParisBounds.getCenter().latitude+(mMap.getCameraPosition().zoom-zoom)*0.001,ParisBounds.getCenter().longitude+(mMap.getCameraPosition().zoom-zoom)*0.001);
zoom = mMap.getCameraPosition().zoom;
// I apply this new bounds on the map and it automatically delete the previous one
mMap.setLatLngBoundsForCameraTarget(ParisBounds.including(chgtBounds));
}
I create a new variable that save the zoom value to know when the user is zooming in the map. When he does it, a new boundaries is created by increasing the previous one by a thousandth of the zoom value (not sure it's the right fraction tho but the idea is the same). However, i think those lines are only executed once at the app's launching. Is there a way to execute them eternally ?
I tried a while(true) but then the app doesn't launch at all.
Current zoom level is obtained from:
mMap.getCameraPosition().zoom
See docs.
The max zoom (used in OP code) is the maximum possible zoom based on current camera position and tile type in use.

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.

Programmatically translate chart in MPAndroidChart

I'm trying to implement custom gesture logic for a CombinedChart in MPAndroidChart. Effectively, what I want to accomplish is to have a long press 'enable' highlighting of values but a short press & swipe just control panning / translating the chart (when zoomed). This would allow you to highlight values in a zoomed viewport without translating the chart (by long pressing before scrolling), but would also allow you to translate the chart if you wish by scrolling the view before the long press registers. I have figured out how to do all of the gesture interactions I want however I cannot figure out how to translate the chart.
All I'm really looking for is a API that allows me to translate the chart viewport by (dX, dY) in pixels but I can't seem to find anything. The closest I can find is CombinedChart.centerViewTo(...) but this expects you to center over data point values which if used when translating creates a bit of a staggered translation (as you cannot center over a value in-between two data points.
I can include code if needed, but I figured the code may be overly verbose for a simple API query.
So, I'll delete this when / if a better answer arises, but I found a way that suits my needs (yet may not be 'idiomatic'). What I did was the following:
(Given an offset in pixels of (dX, dY) and a CombinedChart named mChart...)
ViewPortHandler vph = mChart.getViewPortHandler();
Matrix transformation = vph.getMatrixTouch();
transformation.postTranslate(-dX, -dY); // unset the negs to make x / y inverted
vph.refresh(transformation, mChart, true);

How to preserve the zoom state with JFreeChart?

I am using JFreeChart to draw a graph based on some input values. Once the graph is drawn, I zoom the graph by dragging the mouse. Now, I change the input values and draw the graph again based on the new input values supplied by me. I want the graph should come in the last zoom state which I zoomed earlier.
I have used the following, but is always coming to center and some other zoom position.
double zoomX = chartPanel.getScaleX();
double zoomX = chartPanel.getScaleX();
chartPanel.zoomInBoth(zoomX, zoomY);
Can anyone help me in this, how to achieve this ? Thanks in advance.

Android AchartEngine

I need to implement a Bar chart Where it reads values when the user touches the graph to move it vertically. The graph moves up, recording the value in accordance with the axis . With x axis being the value and the Y axis being the variables , i need to perform calculations. Example to understand
Take a look at this example. You can also do mChartView.addPanListener and handle this event for what you need.

Categories

Resources