简体   繁体   中英

How to add dates dynamically on x-axis on line graph in android

GraphView graph = (GraphView) findViewById(R.id.graph);
GridLabelRenderer gridLabel = graph.getGridLabelRenderer();
gridLabel.setHorizontalAxisTitle("Dates");
gridLabel.setVerticalAxisTitle("Status");

for (int i = 10; i >= 1; i--) {
    Calendar pastDate = Calendar.getInstance();
    pastDate.add(Calendar.DATE, -i);
    String beforedate = pastDate.get(Calendar.DATE) + "/" +(pastDate.get(Calendar.MONTH) + 1) + "/" + pastDate.get(Calendar.YEAR);

    Log.i("paste date is:", beforedate);
}

尝试这个

gridLabel.setHorizontalLabels(new String[]{"1/1/1970", "1/2/1970", "1/3/1970"});

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