how can i show android studio app's the time interval like thingspeak's chart?

this is my thingspeak chart
</matlabcentral/answers/uploaded_files/135202/thingspeak%E5%9C%96.PNG> I want to show Field 1 2 3 chart and this is my android studio app chart
</matlabcentral/answers/uploaded_files/135203/app%E5%9C%96.png> the time interval can't show like thingspeak's chart and this is my code package com.macroyau.thingspeakandroid.demo;
import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast;
import com.macroyau.thingspeakandroid.ThingSpeakChannel; import com.macroyau.thingspeakandroid.ThingSpeakLineChart; import com.macroyau.thingspeakandroid.model.ChannelFeed;
import java.time.DayOfWeek; import java.time.Month; 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 AppCompatActivity {
private ThingSpeakChannel tsChannel;
private ThingSpeakLineChart tsChart,tsChart2,tsChart3;
private LineChartView chartView,chartView2,chartView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Connect to ThinkSpeak Channel 9
tsChannel = new ThingSpeakChannel(566541);
// 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.DAY_OF_MONTH,-2);
//calendar.roll(Calendar.DATE, 1); // 只增加月的欄位值為10個月
// Configure LineChartView
chartView = findViewById(R.id.chart);
chartView2 = findViewById(R.id.chart2);
chartView3 = findViewById(R.id.chart3);
chartView.setZoomEnabled(true);
chartView.setValueSelectionEnabled(true);
chartView2.setZoomEnabled(true);
chartView2.setValueSelectionEnabled(true);
chartView3.setZoomEnabled(true);
chartView3.setValueSelectionEnabled(true);
// Create a line chart from Field1 of ThinkSpeak Channel 9
tsChart = new ThingSpeakLineChart(566541, 1);
tsChart2 = new ThingSpeakLineChart(566541,2);
tsChart3 = new ThingSpeakLineChart(566541,3);
// Get 200 entries at maximum
tsChart.setNumberOfEntries(50);
// Set value axis labels on 10-unit interval
tsChart.setValueAxisLabelInterval(8);
// Set date axis labels on 5-minute interval
tsChart.setDateAxisLabelInterval(-2);
// Show the line as a cubic spline
tsChart.useSpline(false);
// 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);
}
});
// Load chart data asynchronously
tsChart.loadChartData();
tsChart2.setNumberOfEntries(30);
// Set value axis labels on 10-unit interval
tsChart2.setValueAxisLabelInterval(10);
// Set date axis labels on 5-minute interval
tsChart2.setDateAxisLabelInterval(10);
// Show the line as a cubic spline
tsChart2.useSpline(false);
// Set the line color
tsChart2.setLineColor(Color.parseColor("#D32F2F"));
// Set the axis color
tsChart2.setAxisColor(Color.parseColor("#455a64"));
// Set the starting date (5 minutes ago) for the default viewport of the chart
tsChart2.setChartStartDate(calendar.getTime());
// Set listener for chart data update
tsChart2.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
chartView2.setLineChartData(lineChartData);
// Set scrolling bounds of the chart
chartView2.setMaximumViewport(maxViewport);
// Set the initial chart bounds
chartView2.setCurrentViewport(initialViewport);
}
});
// Load chart data asynchronously
tsChart2.loadChartData();
tsChart3.setNumberOfEntries(30);
// Set value axis labels on 10-unit interval
tsChart3.setValueAxisLabelInterval(2);
// Set date axis labels on 5-minute interval
tsChart3.setDateAxisLabelInterval(10);
// Show the line as a cubic spline
tsChart3.useSpline(false);
// Set the line color
tsChart3.setLineColor(Color.parseColor("#D32F2F"));
// Set the axis color
tsChart3.setAxisColor(Color.parseColor("#455a64"));
// Set the starting date (5 minutes ago) for the default viewport of the chart
tsChart3.setChartStartDate(calendar.getTime());
// Set listener for chart data update
tsChart3.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
chartView3.setLineChartData(lineChartData);
// Set scrolling bounds of the chart
chartView3.setMaximumViewport(maxViewport);
// Set the initial chart bounds
chartView3.setCurrentViewport(initialViewport);
}
});
// Load chart data asynchronously
tsChart3.loadChartData();
}
}
Thank you for everyone

Answers (0)

Communities

More Answers in the  ThingSpeak Community

Asked:

on 7 Oct 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!