Error with insertValue in EditableChartDataMo

Help
2010-04-27
2013-04-17
  • Konstantinos Katsaros

    Hey
    I'm new with this. I downloaded the JOpenChart Toolkit and used the 8th tutorial " Oh I'm Manipulatable and it swings"

    It throws the following exception:

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
    at java.util.Vector.elementAt(Vector.java:447)
    at test_chart.GetData.actionPerformed(GetData.java:56)
    at javax.swing.Timer.fireActionPerformed(Timer.java:293)
    at javax.swing.Timer$DoPostEvent.run(Timer.java:224)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

    In this line

    Cdata.insertValue(0, new Double(Data.elementAt(Data.size()).doubleValue()), new Double(time));
    

    Cdata is an EditableChartDataModel and Data is a Vector<integer>.
    I just want to add the last element of the Vector in the graph.

     
  • Konstantinos Katsaros

    I have initialised the Data model like this

        public void initialize(){
            double[][] model = new double [2][Data.size()];
            double [] coloums = new double [Data.size()];
            for (int index = 0; index < Data.size(); index++){
                model [0][index] = Data.elementAt(index).doubleValue();
                model[1][index] = 0;
                coloums [index] = index+1;
            }
            String[] rows = {"Courrent Value", "UWMA Value"};
               
            String title = "Viewing Current and Averaged data from network";
    
            // Create an editable chart data model
            Cdata = new EditableChartDataModel(model, coloums, rows);
            // Creating the Swing ChartPanel instead of DefaultChart
            panel = new ChartPanel(Cdata, title, DefaultChart.LINEAR_X_LINEAR_Y);
            // Adding ChartRenderer as usual
            panel.addChartRenderer(new LineChartRenderer(panel.getCoordSystem(), Cdata), 1);
            // Register EventListener
            Cdata.addChartDataModelListener(this);
    
            setSize(640, 480);
            this.getContentPane().add(panel, BorderLayout.CENTER);
        }
    
     

Log in to post a comment.