4

我创建了一个图表,显示测试期间回答的问题 (X) / 时间 (Y)。您可以在此处查看第一个问题以了解详细信息。

但现在我需要正确显示图表项目符号值,目前显示毫秒值,但我需要显示自定义 hh:mm:ss 值,就像我对 Y 轴标签所做的那样,并以某种方式自定义 Y 轴区域以正确显示完整值。下面是图表现在的样子的屏幕截图。

图表问题/预计回答时间

[编辑]

在丹的帮助下,我几乎得到了我想要的。这只是一个小问题。在下面的屏幕截图中查看图表值现在出现的位置。我从 AChartEngine 存储库更新到 1.1.0。addNotations 在 TimeSeries 对象上。我将代码复制粘贴到下面,将数据添加到我的 TimeSeries 实例。

myQuestionsTimeSeries.add(i, DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()));
                xyMultipleSeriesRenderer.addYTextLabel(DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()),
                        String.valueOf(answer.getEstimatedAnswerTime()));
                myQuestionsTimeSeries.addAnnotation(String.valueOf(answer.getEstimatedAnswerTime()), i,
                        DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()));

此图表的代码结果:

我现在的图表

[编辑]

这基本上是整个班级:

private void initQuestionsTimeChart() {
        xyMultipleSeriesDataset = new XYMultipleSeriesDataset();
        xyMultipleSeriesRenderer = new XYMultipleSeriesRenderer();
        questionsTimeChart = ChartFactory.getLineChartView(getActivity(), xyMultipleSeriesDataset, xyMultipleSeriesRenderer);
        rootView.addView(questionsTimeChart);

        initSeriesData();
    }

    private void initSeriesData() {
        createMyQuestionsSeries();
        addSeriesAndRenderer(myQuestionsTimeSeries, myQuestionsRenderer);

        xyMultipleSeriesRenderer.setYTitle("Questions Time");
        xyMultipleSeriesRenderer.setXTitle("Questions Number");
        xyMultipleSeriesRenderer.setMarginsColor(Color.argb(0, 255, 255, 255));
        xyMultipleSeriesRenderer.setAxesColor(Color.BLACK);
        xyMultipleSeriesRenderer.setLabelsColor(Color.BLACK);
        xyMultipleSeriesRenderer.setXLabelsColor(Color.BLACK);
        xyMultipleSeriesRenderer.setYLabelsColor(0, Color.BLACK);
        xyMultipleSeriesRenderer.setAxisTitleTextSize(16);
        xyMultipleSeriesRenderer.setLabelsTextSize(15);
        xyMultipleSeriesRenderer.setYLabelsAlign(Paint.Align.RIGHT);
        xyMultipleSeriesRenderer.setSelectableBuffer(20);
        xyMultipleSeriesRenderer.setYLabels(0);
        xyMultipleSeriesRenderer.setMargins(new int[]{ 80, 80, 80, 80 });
    }

    private void addSeriesAndRenderer(XYSeries series, XYSeriesRenderer renderer) {
        xyMultipleSeriesDataset.addSeries(series);
        xyMultipleSeriesRenderer.addSeriesRenderer(renderer);
    }

    private void createMyQuestionsSeries() {
        myQuestionsTimeSeries = new TimeSeries("My Questions/Time");
        myQuestionsRenderer = new XYSeriesRenderer();
        myQuestionsRenderer.setColor(Color.BLUE);
        myQuestionsRenderer.setLineWidth(3f);
        myQuestionsRenderer.setPointStyle(PointStyle.CIRCLE);
        myQuestionsRenderer.setFillPoints(true);
        myQuestionsRenderer.setChartValuesSpacing(10f);
    }

    private void fillData() {
        int i = 0;
        for (Answer answer : getAnswers()) {
            i++;
            if (answer.getEstimatedAnswerTime() != null) {
                myQuestionsTimeSeries.add(i, DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()));
                xyMultipleSeriesRenderer.addYTextLabel(DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()),
                        String.valueOf(answer.getEstimatedAnswerTime()));
                myQuestionsTimeSeries.addAnnotation(String.valueOf(answer.getEstimatedAnswerTime()), i,
                        DateTimeHelper.getMillisFromTime(answer.getEstimatedAnswerTime()));
            }
        }
    }

先感谢您!

4

1 回答 1

7

首先,隐藏图表值:

renderer.setDisplayChartValues(false);

然后,为每个图表值添加注释:

renderer.addAnnotation("text", x, y);

要使 Y 轴标签可见,只需将它们对齐到 LEFT:

renderer.setYLabelsAlign(Align.LEFT);

或者您可以增加边距:

renderer.setMargins(margins);

确保您使用的是此处提供的最新 ACE 版本。

于 2013-02-26T10:42:36.190 回答