Error in timeseries

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
lgarcia3
Posts: 43
Joined: Thu Jul 21, 2005 4:00 pm

Error in timeseries

Post by lgarcia3 » Sat Nov 10, 2007 9:10 am

I am feeding a time series with data from intra-day, 5-minute futures. The data goes from 8:00 am to 3:10 pm. I pull the data from a database and try to add to the time series like this

Code: Select all

            TimeSeries close = new TimeSeries("Close");
            Connection conn = this.getConnection();
            String sql = "SELECT * FROM five_minute_data;";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            
            while (rs.next()) {                
                String date = rs.getString("m_date").trim();
                String hour = rs.getString("m_time").trim();
                String[] dateD = date.split("/");
                String[] hourMin = hour.split(":");
                int hourInt = Integer.parseInt(hourMin[0]);
                int min = Integer.parseInt(hourMin[1]);
                int year = Integer.parseInt(dateD[2]);
                int month = Integer.parseInt(dateD[0]);
                int dateInt = Integer.parseInt(dateD[1]);
                System.out.println(date + " " + hour);                
                close.add(new Minute(min,hourInt,dateInt,month,year), rs.getDouble("close"));
            }
And I get this error:

Exception in thread "AWT-EventQueue-1" org.jfree.data.general.SeriesException: You are trying to add data where the time period class is org.jfree.data.time.Minute, but the TimeSeries is expecting an
instance of org.jfree.data.time.Day.
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:497)
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:570)
at org.jfree.data.time.TimeSeries.add(TimeSeries.java:556)
at com.luisegarcia.mainApplet.MainPanel.initialSeries(MainPanel.java:227)
at com.luisegarcia.mainApplet.MainPanel.addClose(MainPanel.java:112)
at com.luisegarcia.mainApplet.MainPanel.access$200(MainPanel.java:46)
at com.luisegarcia.mainApplet.MainPanel$3.actionPerformed(MainPanel.java:97)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1216)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1257)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

I tried with the method addOrUpdate and the errors does not come up; but instead of getting 3000 points on the plot as I should I end up with about 80 or so. I guess the method is just overwriting the data.
Any ideas?

lgarcia3
Posts: 43
Joined: Thu Jul 21, 2005 4:00 pm

Post by lgarcia3 » Mon Nov 12, 2007 8:11 pm

Never mind, I figured it out. There is a constructor to indicate the type of time data to pass to the class like this

Code: Select all

new TimeSeries("Price",Minute.class);

Locked