현재 마이크로 컨트롤러 보드로 블루투스 통신을 통해받은 데이터를 플롯하려고합니다. 각 데이터 전송 (200ms마다)은 내 안드로이드 장치에 4 자 (4 자리)의 문자열을 전송하며 새로운 데이터가있을 때마다 업데이트되는 textView로 값을 표시 할 수 있습니다. 이것은 MainActivity에서 10 초 동안 발생합니다. androidplot을 사용하여 문자열 배열의 플롯 데이터
내가 같은 문자열 목록의 각 문자열을 저장하고로부터 데이터를 플롯 할 배열을 얻으려면 : IST 나는 간단한 xyPlot에서 복사 한 활동 xyPlot (전송// Create Array List to send to xyPlot activity
List<String> incomingStringData = new ArrayList<>();
// more code happening...
String loadCellString = recDataString.substring(1, 5); // get sensor value from string between indices 1-5
incomingStringData.add(loadCellString); // Adding each incoming substring to List<String> incomingStringData
// more code happening
// On button click send data to xyPlot activity
btnPlot.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent xyPlotScreen = new Intent(getApplicationContext(), xyPLot.class);
//Sending data to another Activity
String[] xyPlotStringArray = incomingStringData.toArray(new String[0]);
xyPlotScreen.putExtra("string-array", xyPlotStringArray);
// Start plotscreen (xyPlot) activity
startActivity(xyPlotScreen);
}
}
이 데이터 androidplot의 예는, 감사는 BTW) 다음과 같이 처리된다 :
// Get String Array from Motor Control (MainActivity):
Intent xyPlotScreen = getIntent();
String[] thrustStringArray = xyPlotScreen.getStringArrayExtra("string-array");
// Convert String-Array into an Integer to be able to plot:
String[] parts = thrustStringArray[0].split(",");
Integer[] intThrust = new Integer[parts.length];
for(int n = 0; n < parts.length; n++) {
intThrust[n] = Integer.parseInt(parts[n]);
}
// Create the Number series for plotting
Number[] thrustSeries = intThrust;
// Turn the above arrays into XYSeries':
// (Y_VALS_ONLY means use the element index as the x value
XYSeries thrustSeries = new SimpleXYSeries(Arrays.asList(thrustArray),
SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,"Thrust");
이 지금 나는 내가 무엇입니까 들어오는 데이터를 그릴 수 있다면 바로 알고 XY_VALS_INTERLEAVED
를 사용, 그것은 이해가되지 않는 경우에도 (나중에 내 문자열은 타임 스탬프로 구성됩니다. x 축).
데이터 유형 "숫자"(이는 또한 정수형입니까?)는 물론 문자열 배열을 지원하지 않습니다. 그래서 String에서 정수로 변환 한 다음 앱을 만들 수있었습니다. 내 로이드 장치에서 들어오는 데이터의 주파수를 변경할 때 I (초당 1 개 값이므로 10 개 값)도
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.controlcenter.controlcenter/com.controlcenter.controlcenter.xyPLot}: java.lang.IndexOutOfBoundsException: Cannot auto-generate series from odd-sized xy List.
: I가 플롯 활동을 시작하면
난 이 오류 메시지 같은 오류 메시지가 나타납니다. 문제는 내가 문자열을 Integer로 변환하는 부분 근처에 있다고 생각합니다. 그러나 Number[]
데이터 유형의 센서 데이터를 플롯하기 위해이 변환을 올바른 방법으로 수행하는 방법을 찾을 수 없었습니다.
당신이 도와 주길 바랍니다.
미리 감사드립니다. Chris
답장을 보내 주셔서 감사합니다. 나는 당신의 코드 스 니펫을 포함 시켰습니다. java.lang.RuntimeException : 액티비티를 시작할 수 없습니다. ComponentInfo {com.controlcenter.controlcenter/com.controlcenter.controlcenter.xyPLot} : java.lang.NumberFormatException : 유효하지 않은 int : "70 "' – hohmchri
아마도 숫자로 파싱하는 데이터가 손상되었거나 파싱하는 방식이 올바르지 않습니다. – Nick