How to display values in Bar chart in Android


#1

I want to display speed variable value on bar chart so any one have any sample example or link to get some idea.

Here is something i done please correct me : Note on button click i will display Speed value on bar chart.

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    private Button mGetButton;
    private GraphView graphView1

    private Timer getTimer1

    ActivityManager manager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        //mbatteryLvel = (TextView) findViewById(R.id.Speed);
        mGetButton = (Button) findViewById(R.id.getButton);
        graphView1 = (GraphView) findViewById(R.id.graph_speed);
   
        mGetButton.setOnClickListener(this);

        /** Create graph **/
        Utils.createGraph(graphView1, Utils.speedMap);
  
public static void createGraph(GraphView graphView, String mapTitle) {
        series = new LineGraphSeries<DataPoint>();
        series.setTitle(mapTitle);
        series.setDrawDataPoints(true);
        series.setDataPointsRadius(7);
        graphView.addSeries(series);
        graphView.setTitle(mapTitle);

        viewPort = graphView.getViewport();
        viewPort.setYAxisBoundsManual(true);
        viewPort.setXAxisBoundsManual(true);

        graphView.getViewport().setXAxisBoundsManual(true); //Rama

        viewPort.setMinX(0);
        viewPort.setMaxX(100);

       if (mapTitle == Utils.rpmMap)
            viewPort.setMaxY(16000);
        else
           viewPort.setMaxY(300);

        viewPort.setMinY(0);

        viewPort.setScrollable(true);


    }

class to start Asynctask:

public class GetSpeedData extends TimerTask {

    GraphView graphView;

    GetSpeedData (GraphView graphView) {
        Log.d("GetspeedData", "Constructor");
        this.graphView = graphView;
    }

    @Override
    public void run() {
        new GetAsyncTask(graphView).execute();
    }
}

please suggest how to display speed value in bar chart in android.


#2

Hello @HULK,

For the using of charts with Android, we recommend you to use AndroidChart.

For more information about Ubidots, reference to the Ubidots REST API Reference.

All the best,
Maria C.