Results 1 to 9 of 9

Thread: JFreeChart help

  1. #1
    lowlyintern is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default 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);
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Could you explain where your problems are in the code? I don't see any comments saying *** HERE ***
    or any reference to "mercury".

  3. #3
    lowlyintern is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    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.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Could you execute the program, take a screen shot and note on the image what values you are looking for?

  5. #5
    lowlyintern is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default


  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

  7. #7
    lowlyintern is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    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.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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.

Similar Threads

  1. JFreeChart 1.0.11
    By Java Tip in forum Java Software
    Replies: 3
    Last Post: 04-18-2014, 09:27 PM
  2. Jfreechart
    By aaruviswa in forum Web Frameworks
    Replies: 2
    Last Post: 03-17-2011, 07:51 AM
  3. Jfreechart help
    By shruti in forum AWT / Swing
    Replies: 1
    Last Post: 07-11-2009, 05:16 AM
  4. JFreeChart 1.0.8
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-27-2007, 09:27 PM
  5. JFreeChart 1.0.5
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-10-2007, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •