Create AChartEngine TimeChart using Time in Y-Axis

2019-08-03 18:07发布

问题:

I have some data representing answered questions in particular time e.g.

Question 1 answered in 00:00:20. I am trying to use AChartEngine to represent this but with no luck. First of all I can't have Y values as this format for a reason, guess it's not supported or needs customization which couldn't find a way till now to achieve.

My chart should have in the end the X-Axis with values 1, 2, 3, 4, 5.... and Y-Axis with 00:00:20, 00:00:15, 00:00:05, 00:00:10.... The time achieved in each question is saved in a Time object field. I try this approach:

private void fillData() {
        int i = 0;
        for (Answer answer : getAnswers()) {
            i++;
            if (answer.getEstimatedAnswerTime() != null) {
                Log.d(TAG, String.valueOf(answer.getEstimatedAnswerTime()));
                myQuestionsTimeSeries.add(new Date(DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime())), i);
            }
        }
    }

First problem, can't get the time values to Y-Axis and not shown correctly anyway. See screenshot below.

I guess you get my point so far. Thank you in advance.

回答1:

The TimeChart displays formatted date labels on the X axis. It seems like you need to do that on the Y axis.

Just create a regular LineChart and add custom labels on the Y axis:

// disable the default Y labels first
renderer.setYLabels(0);
// add several custom labels
renderer.addYTextLabel(y, "label");