简体   繁体   中英

Android - MPAndroid Chart showing x axis value

I have a listview with data in one activity and show that data in a graph in another activity. ListView Data. and displayed on graph.

I want to show the x axis associated with the value("Running", "Swimming")

I'm using an intent to send the value to the graph page and here is the code i'm using to populate the graph.

 ArrayList<String> cardioValue = new ArrayList<String>();
    ArrayList<String> cardioCategory = new ArrayList<String>();
    cardioValue = intent.getStringArrayListExtra("cardioValue");
    cardioCategory = intent.getStringArrayListExtra("cardioCategory");


    ArrayList<BarEntry> barEntries = new ArrayList<>();
    for(int i=0; i<cardioValue.size(); i++ ){

            barEntries.add(new BarEntry( i+1, Integer.parseInt(cardioValue.get(i))));
    }

You will have to use a value formatter to achieve this.

String[] cardioValue = {"", "Running, "Swimming"};
XAxis xaxis = mChart.getXAxis();
xaxis.setValueFormatter(new IndexAxisValueFormatter(cardioValue));

I have kept the first value of the string array empty because your first bar is being formed at value 1. You will have to do the same with array lists.

Link to documentaion.

Working example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM