在這段代碼中,數據來自thingspeak網站給出的頻道ID。該頻道是公開的。該圖是使用hellocharts和chartview獲得的。從thingspeak網站檢索數據到HelloCharts
問題: 我想打印所有在圖形上繪製的數據值或在文本視圖中添加的最後一個數據。在哪個變量中存儲數據正如我想進一步處理數據一樣。
在我想知道的是,值395被存儲在哪個變量輸出。
我已經提供了下面的java代碼。
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
import com.macroyau.thingspeakandroid.ThingSpeakChannel;
import com.macroyau.thingspeakandroid.ThingSpeakLineChart;
import com.macroyau.thingspeakandroid.model.ChannelFeed;
import java.util.Calendar;
import java.util.Date;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;
public class DemoActivity extends ActionBarActivity {
private ThingSpeakChannel tsChannel;
private ThingSpeakLineChart tsChart;
private LineChartView chartView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Connect to ThinkSpeak Channel 9
tsChannel = new ThingSpeakChannel(135855);
// Set listener for Channel feed update events
tsChannel.setChannelFeedUpdateListener(new ThingSpeakChannel.ChannelFeedUpdateListener() {
@Override
public void onChannelFeedUpdated(long channelId, String channelName, ChannelFeed channelFeed) {
// Show Channel ID and name on the Action Bar
getSupportActionBar().setTitle(channelName);
getSupportActionBar().setSubtitle("Channel " + channelId);
// Notify last update time of the Channel feed through a Toast message
Date lastUpdate = channelFeed.getChannel().getUpdatedAt();
Toast.makeText(DemoActivity.this, lastUpdate.toString(), Toast.LENGTH_LONG).show();
}
});
// Fetch the specific Channel feed
tsChannel.loadChannelFeed();
// Create a Calendar object dated 5 minutes ago
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -5);
// Configure LineChartView
chartView = (LineChartView) findViewById(R.id.chart);
chartView.setZoomEnabled(false);
chartView.setValueSelectionEnabled(true);
// Create a line chart from Field1 of ThinkSpeak Channel 9
tsChart = new ThingSpeakLineChart(135855, 2);
// Get 200 entries at maximum
tsChart.setNumberOfEntries(200);
// Set value axis labels on 10-unit interval
tsChart.setValueAxisLabelInterval(10);
// Set date axis labels on 5-minute interval
tsChart.setDateAxisLabelInterval(10);
// Show the line as a cubic spline
tsChart.useSpline(true);
// Set the line color
tsChart.setLineColor(Color.parseColor("#D32F2F"));
// Set the axis color
tsChart.setAxisColor(Color.parseColor("#455a64"));
// Set the starting date (5 minutes ago) for the default viewport of the chart
// tsChart.setChartStartDate(calendar.getTime());
// Set listener for chart data update
tsChart.setListener(new ThingSpeakLineChart.ChartDataUpdateListener() {
@Override
public void onChartDataUpdated(long channelId, int fieldId, String title, LineChartData lineChartData, Viewport maxViewport, Viewport initialViewport) {
// Set chart data to the LineChartView
chartView.setLineChartData(lineChartData);
// Set scrolling bounds of the chart
chartView.setMaximumViewport(maxViewport);
// Set the initial chart bounds
chartView.setCurrentViewport(initialViewport);
/* LineChartData data = new LineChartData();
float data1=data.getBaseValue();
TextView tvName = (TextView)findViewById(R.id.textView);
tvName.setText((int) data1);*/
}
});
// Load chart data asynchronously
tsChart.loadChartData();
}
}
的API,我沒有看到,你甚至獲得X和Y值圖表...'tsChart.loadChartData( );' - 那是幹什麼的? –
看「ThingSpeakLineChart」的源代碼,它不會公開該信息 –