Error with insertValue in EditableChartDataMo

  • Konstantinos Katsaros

    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(
    at test_chart.GetData.actionPerformed(
    at javax.swing.Timer.fireActionPerformed(
    at javax.swing.Timer$
    at java.awt.event.InvocationEvent.dispatch(
    at java.awt.EventQueue.dispatchEvent(
    at java.awt.EventDispatchThread.pumpOneEventForFilters(
    at java.awt.EventDispatchThread.pumpEventsForFilter(
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(
    at java.awt.EventDispatchThread.pumpEvents(
    at java.awt.EventDispatchThread.pumpEvents(

    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
            setSize(640, 480);
            this.getContentPane().add(panel, BorderLayout.CENTER);

Log in to post a comment.