Results 1 to 9 of 9
Thread: JFreeChart help
- 06-15-2011, 01:46 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 13
- Rep Power
- 0
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.
Java 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); } }
- 06-15-2011, 02:22 PM #2
Could you explain where your problems are in the code? I don't see any comments saying *** HERE ***
or any reference to "mercury".
- 06-15-2011, 02:41 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 13
- Rep Power
- 0
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.
- 06-15-2011, 03:48 PM #4
Could you execute the program, take a screen shot and note on the image what values you are looking for?
- 06-15-2011, 03:58 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 13
- Rep Power
- 0
- 06-15-2011, 04:00 PM #6
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.
- 06-15-2011, 04:27 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 13
- Rep Power
- 0
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.
- 06-15-2011, 04:30 PM #8
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.
- 06-15-2011, 04:30 PM #9
Similar Threads
-
Jfreechart
By aaruviswa in forum Web FrameworksReplies: 2Last Post: 03-17-2011, 06:51 AM -
Jfreechart help
By shruti in forum AWT / SwingReplies: 1Last Post: 07-11-2009, 04:16 AM -
JFreeChart 1.0.11
By Java Tip in forum Java SoftwareReplies: 0Last Post: 09-26-2008, 07:52 PM -
JFreeChart 1.0.8
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-27-2007, 08:27 PM -
JFreeChart 1.0.5
By levent in forum Java SoftwareReplies: 0Last Post: 05-10-2007, 05:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks