Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

android - Only one number does not show anything in AndroidPlot

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:

My Code for Line Graph is as follows:

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);

Does somebody have a solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...