-
JFreeChart help
Hey there, I'm having some trouble with the ThermometerPlot in JFreeChart. Basically all I want to do is find the XY-value of where the "mercury" is currently set to on the JPanel/JFrame or what have you.
Code:
package smartt;
import java.awt.*;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.ThermometerPlot;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.data.general.ValueDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
public class DepthPanel extends ApplicationFrame
{
static class ContentPanel extends JPanel
implements ChangeListener
{
JSlider slider;
DefaultValueDataset dataset;
private static JFreeChart createChart(ValueDataset valuedataset)
{
ThermometerPlot depthplot = new ThermometerPlot(valuedataset);
JFreeChart jfreechart = new JFreeChart("Depth Chart", JFreeChart.DEFAULT_TITLE_FONT, depthplot, true);
depthplot.setInsets(new RectangleInsets(5D, 5D, 5D, 5D));
depthplot.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
depthplot.setThermometerStroke(new BasicStroke(2.0F));
depthplot.setThermometerPaint(Color.lightGray);
depthplot.setBulbRadius(0);
depthplot.setUnits(ThermometerPlot.UNITS_NONE);
depthplot.setGap(5);
depthplot.setUpperBound(0);
depthplot.setLowerBound(-1500);
System.out.println(depthplot.getRangeAxis().toString());
return jfreechart;
}
public void stateChanged(ChangeEvent changeevent)
{
dataset.setValue(new Integer(slider.getValue()));
}
public ContentPanel()
{
super(new BorderLayout());
slider = new JSlider(-1500, 0);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setMajorTickSpacing(100);
slider.addChangeListener(this);
add(slider, "South");
dataset = new DefaultValueDataset(slider.getValue());
add(new ChartPanel(createChart(dataset)));
}
}
public DepthPanel(String s)
{
super(s);
JPanel jpanel = createDemoPanel();
setContentPane(jpanel);
}
public static JPanel createDemoPanel()
{
return new ContentPanel();
}
public static void main(String args[])
{
DepthPanel thermometerdemo1 = new DepthPanel("Depth");
thermometerdemo1.pack();
thermometerdemo1.setVisible(true);
}
}
-
Could you explain where your problems are in the code? I don't see any comments saying *** HERE ***
or any reference to "mercury".
-
My bad, by "mercury" I just meant the the rounded rectangle that is used to denote what the current temperature is which is currently set by the slider. And it's not so much that there's a problem in the code but just a lack of knowledge on my part on how to retrieve the dimensions/location of that rounded rectangle or just the XY-value of top of that rectangle on the JPanel. Everything I've tried (trying to get ChartRenderingInfo/methods in ThermometerPlot or Plot) has been a dead end but I may have missed something in there. The code above is just a demonstration of what I'm talking about.
-
Could you execute the program, take a screen shot and note on the image what values you are looking for?
-
-
What jar file do you need to compile the above code?
Have you read the API doc for the JFreeChart classes? I would think there are methods or callbacks or listeners to use to give you the info you want.
-
Just JFreeChart and JCommon http://sourceforge.net/projects/jfreechart/files/. And I've gone through all of the applicable API docs for ThermometerPlot to no avail.
-
How does ThermometerPlot use the ValueDataset value?
That appears to be connected to the slider which sends the data that controls the height of the column being displayed.
-
How does ThermometerPlot use the ValueDataset value?
That appears to be connected to the slider which sends the data that controls the height of the column being displayed.