how to add zoom functionality to chart created by jfreechart - java

I have drawn a XY chart using jfree. Now i want to add zoom functionality to it. This must be done using a slider at the bottom of the chart. How can i add zoom functionality, the likes of which is present in Windows Photo Viewer?
Also, i would like to show the current Y-value of the graph as a tooltip when the user hovers his mouse over the plotted line. I am not getting much ideas.
Please help.
Thanks in advance

XYPlot et al. implement the Zoomable interface, which allows ChartPanel to control zooming. I'd think you could use these methods in your slider's ChangeListener.
I would like to show the current Y-value of the graph as a tooltip…
You can enable tool tips, as shown in this example.

Related

Show stacked bar chart in Application

How can I show chart shown in below image in my App? It is shown in Settings->Apps->Running. I tried Microcharts but it isn't possible using it. I want to show it for storage space. I know how to get the storage space values but don't know how to plot chart like in the image.
You mean a stacked bar diagram. It is possible with NumAndroidCharts Library, in this example they make a horizontal one. Maybe you are able to use it vertical as well:
https://www.numetriclabz.com/android-stacked-bar-chart-using-numandroidcharts-tutorial/
But i don't now if you can hide the X and Y coord description, so it would look like in your picture. Maybe it is easier for you to draw it on your own, the diagram are simple rectangles.
Update
Found the horinzontal one:
https://www.numetriclabz.com/android-horizontal-stacked-bar-using-numandroidcharts-tutotrial/

Android Customized Barchart

I need to create a chart like this picture bellow in Android.
and I am already aware of MPAndroidChart and AndroidHelloCharts libraries. but none of them are capable of drawing such thing.
do you know any way to create a chart like this?
please explain and at least suggest me some tutorials or articles that are related to what I am about to do.
thank you
Its actually pretty simple to create your own bar chart.
First you need to use drawRect to draw a rectangle.
And then drawText to draw text below the rectangle.
You may have noticed that both methods take a paint object as the parameter , you can think of the paint object like a brush. So you set the color to the brush and draw different elements.
I have written about it
here

show tooltip using layout coordinates

Basically I want to show a javafx.scene.control.Tooltip using screen coordinates.
In a Scene I have a couple of Node instances that each have their own Tooltip instance. A certain event should trigger all nodes to show their tooltips at the same time. (It's a kind of help feature)
But the show methods use screen coordinates. So when I use tooltip.show(node, node.getLayoutX(), node.getLayoutY()) unfortunately all tooltips are off a couple of inches.
Using mouse events, I would have used the mouseEvent.getScreenX() and mouseEvent.getScreenY() methods to show the tooltip. But unfortunately, I'm not using the mouse to trigger this event, this time.
A Node doesn't have getScreenX methods. So, is there a way to convert the layout coordinates to screen coordinates ?
If there is an alternative approach, feel free to share as well.
There is no way to convert directly from layout coordinates to screen coordinates. But there is a method localToScreen which can be used to convert the local coordinates to screen coordinates.
Bounds bounds = node.localToScreen(getBoundsInLocal());
tooltip.show(this, bounds.getMinX(), bounds.getMinY());

Java JFreeChart: customize tooltip screen position

I implemented my own JFreeChart XYToolTipGenerator and, as the chart it is used on is almost full screen, sometimes the tooltip position (on screen) hides the point it is related to (e.g. in the bottom right corner, since it seems that tooltip is configured to be positioned South-East of the mouse / data point). This is a problem because the user needs to be able to click on the chart's data points (as it generates a specific action).
Is there a way to either define dynamically the position of the tooltip (e.g. for data points bottom right I would ask the tooltip to be shown North-West) or, alternatively, to define a systematic position (e.g. North-West instead of South-East as it is by default)?
This problem has given me headaches for the last few days - any help or hint is more than welcome.
Many thanks!
Thomas
Here's the answer I posted on the JFreeChart forum:
JFreeChart is using the standard Swing tool tip mechanism. In the ChartPanel class, the getToolTipText(mouseEvent) method is overridden to return the appropriate text for the tooltip, and that's it.
Swing also gives you the option to override the getToolTipLocation(mouseEvent) method, and that's probably what you need here.

JFreeChart drag plot area

I would like to be able to drag the plot area to be able to move the x-axis across.
Is this possible?
It certainly is. Check out this Java Web Start demo. The XYPlot (for example) supports the Pannable interface.

Categories

Resources