简体   繁体   中英

need help on achartengine for android

I have created an application in Android to read certain sensor values using Arduino board. Now i am trying to use the achartengine to draw the graph for one of the sensors. I have chosen the line chart / sensor value chart of achartengine.

 values.add(new double[] { 21.2, 21.5, 21.7, 21.5, 21.4, 21.4, 21.3, 21.1, 20.6, 20.3, 20.2, 19.9, 19.7, 19.6, 19.9, 20.3, 20.6, 20.9, 21.2, 21.6, 21.9, 22.1, 21.7, 21.5 }); values.add(new double[] { 1.9, 1.2, 0.9, 0.5, 0.1, -0.5, -0.6, MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -1.8, -0.3, 1.4, 3.4, 4.9, 7.0, 6.4, 3.4, 2.0, 1.5, 0.9, -0.5, MathHelper.NULL_VALUE, -1.9, -2.5, -4.3 });

All the values i get from the sensor are stored in a variable (for example: sens). How can i declare that variable in this line.

    

 values.add(new double[] { 21.2, 21.5, 21.7, 21.5, 21.4, 21.4, 21.3, 21.1, 20.6, 20.3, 20.2,19.9, 19.7, 19.6, 19.9, 20.3, 20.6, 20.9, 21.2, 21.6, 21.9, 22.1, 21.7, 21.5 });

The sens variable is declared here. There are some calculations and shifting bits before first line.


           byte bvolt1 = voltage[0];
        int ReadRaw = bvolt1;
            double temp = ReadRaw ;
            double  sens = (tmp3*0.00592) + 1.82;
            sens = sens * 10;
            sens = Math.round(sens);
            sens = sens / 10;
            Voltage.setText(String.valueOf("Voltage is : " + sens));  


Thanks

One way you could do it is to store the values you get from your sensors into an ArrayList. You could use something like this

//add this declaration to your file
ArrayList<double> sensorValues;

//now anytime you take a new reading from your sensor add it to the array list.
sensorValues.add(newReadingFromSensor);


//when you want to make your chart do it like this.
values.add(sensorValues.toArray());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM