Skip to content Skip to sidebar Skip to footer

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 th

Solution 1:

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.

Solution 2:

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.

publicclassGraphViewextendsView
{
    ...
    privatefinalRectrect=newRect();
    privatefinalPaintlinePaint=newPaint();
    privatefinalPaintbackgroundPaint=newPaint();
    privatefloat[] points;

    publicGraphView(final Context context, final AttributeSet aSet)
    {
        super(context, aSet);
    }
    @OverrideprotectedvoidonDraw(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)

Solution 3:

I suggest you use AChartEngine rather than drawing to canvas. You can download the library, javadocs and a demo application here.

There are tutorials on youtube on getting started with AChartEngine.

You can use line charts with the area below chart filled with a color or not filled for copying the functionality in the first screenshots you provided.

Post a Comment for "How To Draw A Graph In Android Like Wifi Analyzer App?"