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

    Default Messing around with JFreeCharts

    Hello there, I'm making a depth meter of sorts that will eventually be taking constant updates. I've been using a modified version of the ThermometerPlot class from JFreeCharts to do so. The idea is to make the plot look like a rectangle with bumps on either end and have a seperate image move up and down it based on where the thermometer value would be.

    Java Code:
    // Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
    // Jad home page: http://kpdus.tripod.com/jad.html
    // Decompiler options: packimports(3) fieldsfirst ansi space 
    
    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());
                
                
    //            thermometerplot.setDisplayRange(1000, 0, -3000);
    
                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);
    	}
    }
    My question is if there's any way to get the paint coordinates of where the depth is and I'll just set the image center to there. If that's not possible, do you have any suggestions for what I can do?

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

    Default

    I think I may have gotten a bit closer on my own. It appears that the ChartPanel would be able to yield the necessary data to get this going. However, the getChartRenderingInfo() method claims there isn't and entities in the chart. Can anyone explain why that would be happening/have some insight in how JFreeChart would handle the particular elements in the panel?

Posting Permissions

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