本文介绍了AndroidPlot中只有一个数字不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示用户尝试的问题/答案会话的折线图和条形图.我正在使用AndroidPlot 0.6.0.会话日期时间是域,范围是用YesNo回答的问题的数量.

I want to display line and bar graph for question/answer session attempted by user. I am using AndroidPlot 0.6.0. Session date time is domain and Range is count of questions answered with Yes or No.

问题:带有单个项目的列表在图形中未显示任何内容.例如,用户第一次会话:

Issue: List with single item does not show anything in the graph. For example, user first session:

至少包含两个项目的列表可以正确显示图形.该图正确显示了两个会话,其中日期为域,计数为是/否为范围:

List with at least two items show graph correctly. Graph correctly shows two sessions with date as domain and count of yes/no as range:

我的折线图代码如下:

XYSeries answeredYesSeries = new SimpleXYSeries(answeredYesList,
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, 
// Y_VALS_ONLY means use the element index as the x value
                "Answered Yes"); // Title of this series
        // Create a formatter to use for draw ing a series using
        // LineAndPointRenderer
        // and configure it from xml:
        LineAndPointFormatter series1Format = new LineAndPointFormatter();
        series1Format.setPointLabelFormatter(new PointLabelFormatter());
        series1Format.configure(getApplicationContext(),
                R.xml.line_point_formatter_with_plf1);

        // add count of questions answered with yes series to the xyplot:
        xyPlot.addSeries(answeredYesSeries, series1Format);

        XYSeries answeredNoSeries = new SimpleXYSeries(answeredNoList,
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means
                                                    // use the element
                                                        // index as the x
                                                        // value
                "Answered No"); // Title of this series
        // Create a formatter to use for draw ing a series using
        // LineAndPointRenderer
        // and configure it from xml:
        LineAndPointFormatter series2Format = new LineAndPointFormatter();
        series2Format.setPointLabelFormatter(new PointLabelFormatter());
        series2Format.configure(getApplicationContext(),
                R.xml.line_point_formatter_with_plf2);

        // add count of questions answered with no series to the xyplot:
        xyPlot.addSeries(answeredNoSeries, series2Format);

有人可以解决吗?

推荐答案

之所以会发生这种情况,是因为Androidplot没有足够的信息来自动计算单个点的合理域/范围比例.

This happens because Androidplot does not have enough information to automatically calculate what a reasonable domain/range scale would be from a single point.

可以说您的数据由点[1,1]组成.应该如何呈现呢? x/y比例应该为0-2吗?很好-如果数据代表的是我一周内吃牛排的数量.但是,如果数据规模庞大,例如1到10,000之间的随机数,该怎么办?或者小数位数在0到1之间.

Lets say your data consists of the point [1,1]. How should should this be presented? Should the x/y scale be 0 - 2? That would be fine - if the data represents something like number of steaks I eat in a week. But what if the data has a vast scale, like a random number between 1 and 10,000? Or what if the scale is between 0 and 1.

Androidplot必须提供此信息,而不是假设可能是有意义的比例(它可以而且可以说应该做到).这是将图形边界固定到固定区域的简单示例:

Rather than assume what a meaningful scale might be (which it could and arguably should do) Androidplot must be provided with this information. Here's a simple example of fixing the graph boundaries to a fixed region:

plot.setDomainBoundaries(-1, 1, BoundaryMode.FIXED);
plot.setRangeBoundaries(0, 2, BoundaryMode.FIXED);

请记住,如果您希望它可见,则需要提出一些边界,以包围要尝试绘制的点.

Keep in mind that you'll need to come up with boundaries that encompass your point that you're trying to draw, if you want it to be visible.

这篇关于AndroidPlot中只有一个数字不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 02:34