Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a graph in android like Wifi Analyzer App?

Hi I'm trying to develop a Field Test Application and i've to retrieve information like signal strength of neighboring cells.

So my question is:

How can I display a graph with the different neighboring cells on X-axis and the signal strength on Y-axis in real time? An example here.

I've already got 5 or 6 neighboring cells and for each one his signal strength.

like image 575
13KZ Avatar asked Jun 19 '12 13:06

13KZ


People also ask

Is there an app that shows Wi-Fi strength?

iWifi is your ultimate network diagnostic tool, you can quickly test your internet speed, detect networked devices and view all kinds of network information, and there is also an analysis tool to visualize the nearby Wi-Fi signal.


2 Answers

Rather drawning the graph your self manually using Canvas, You can use Chart Engine Libraries available and that will be much easier to do also.

Like AchartEngine,ChartDroid,aFreeChart,MPAndroidChart

For 3D Chart Charts4J

How can I display a graph with the different neighboring cells on X-axis and the signal strength on Y-axis in real time?

I have used aChart Engine for the same in one of my application. There is a complete API demo available with the library so it will be pretty easy to understand how to use that.

like image 57
MKJParekh Avatar answered Oct 04 '22 10:10

MKJParekh


I don't know which type of graph you want to develop because there are different types at your link. But I've developed a real time line graph in android. I'm using canvas for drawing lines.

public class GraphView extends View
{
    ...
    private final Rect rect = new Rect();
    private final Paint linePaint = new Paint();
    private final Paint backgroundPaint = new Paint();
    private float[] points;

    public GraphView(final Context context, final AttributeSet aSet)
    {
        super(context, aSet);
    }
    @Override
    protected void onDraw(final Canvas canvas)
    {
        if (points == null)
        {
            return;
        }
        canvas.drawLines(points, linePaint);
        rect.set((int) (xIndex * xScale), 0, (int) (xIndex * xScale + 5), getHeight());
        canvas.drawRect(rect, backgroundPaint);
    }
...
}

You can easily position/size your rect according to your needs. I didn't wrote the calculations of xIndex and xScale. The points array is the one which your values will be written.

But beware, in android lines are drawn with pairs, there is no 'point' structure as I know.

I mean [1, 0.25, 2, 0.45] draws a line between x1= 1, y1=0.25 and x2=2, y2= 0.45

Also you can trigger draw by postInvalidate()

postInvalidate() onDraw (Canvas canvas)

like image 26
GokcenG Avatar answered Oct 04 '22 10:10

GokcenG