Back to project page AndroidGraph.
The source code is released under:
MIT License
If you think the Android project AndroidGraph listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.nimble.android_graph.Graph; /*from w w w .java 2 s .c o m*/ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.os.SystemClock; import android.util.AttributeSet; import com.nimble.android_graph.Graph_Base.Point; /** * Example graph. Displays a real time sine wave. * Created by Michael Leith on 18/07/2014. */ public class SineWave extends LineGraph { double t = 0.1; long prevTime = 0; public SineWave(Context context) { super(context); dataAdjusted = true; useGrid = false; Line line = new Line(); axisColour = Color.parseColor("#000000"); labelColour = Color.parseColor("#000000"); line.setColour(Color.parseColor("#33b5e5")); line.setShadow(Color.parseColor("#0099cc")); line.distBetweenPoints = 2f; addLine(line); prevTime = SystemClock.elapsedRealtime(); } public SineWave(Context context, String xLabel, String yLabel) { this(context); setLabels(xLabel, yLabel); } public SineWave(Context context, AttributeSet attrs) { this(context); setLabels("Time", "Current"); setWillNotDraw(false); this.start(); } public SineWave(Context context, String xLabel, String yLabel, boolean useShadow) { this(context, xLabel, yLabel); lines.get(0).setUseShadow(useShadow); } @Override public void onDraw(Canvas canvas) { float y = 50* (float) Math.sin(t) + 80; addPointToLine(0, new Point(lines.get(0).getNextX(), y)); t +=0.1; super.onDraw(canvas); long currentTime = SystemClock.elapsedRealtime(); paint.setColor(axisColour); canvas.drawText(Float.toString ( 1000f / (float) (currentTime - prevTime) ), 500, 100, paint); prevTime = currentTime; } }