0
votes

Could somebody please explain me what I have to do so that my plot shows me at least any kind of axis caption? The horrible androidplot documentation explains less than nothing.

Code:

    Date day1 = getDate(28, MAY, 2016);
    Date day2 = getDate(29, MAY, 2016);
    Date day3 = getDate(30, MAY, 2016);
    Date day4 = getDate(31, MAY, 2016);
    Date day5 = getDate(1, JUNE, 2016);

    Number[] quotes = new Float[]{4.23f, 5.13f, 5.73f, 6.12f, 4.23f};
    Number[] dates = new Long[]{day1.getTime(), day2.getTime(), day3.getTime(), day4.getTime(), day5.getTime(),};

    XYSeries series = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(quotes), "History 5 days");

    LineAndPointFormatter formatter = new LineAndPointFormatter();
    formatter.setPointLabelFormatter(new PointLabelFormatter());
    formatter.configure(this, R.xml.line_point_formatter_with_labels);

    plot.setDomainStep(XYStepMode.SUBDIVIDE, 5);
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 5);
    plot.setDomainValueFormat(new Format()
    {
        private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.");

        @Override
        public StringBuffer format(Object object, StringBuffer buffer, FieldPosition field)
        {
            long millis = ((Number) object).longValue();
            Date date = new Date(millis);
            return dateFormat.format(date, buffer, field);
        }

        @Override
        public Object parseObject(String string, ParsePosition position)
        {
            return null;
        }
    });
    plot.addSeries(series, formatter);

Plot xml:

<com.androidplot.xy.XYPlot
    android:id="@+id/plot"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginTop="10dp"
    app:domainLabel="domain label"
    app:label="A simple plot"
    app:rangeLabel="range label" />

There couldn´t be less caption:

enter image description here

at the left side I would like to have numbers like 4.0, 5.0, 6.0 and at the bottom the date

1
could you include your plot's xml as well as the version of Androidplot you're using? If you followed the quickstart tutorial you should see these elements. - Nick
updated with plot xml - Lemao1981
the quickstart says absolutley nothing about axis caption. they show an example and the final graph has nice lables. well, mine hasn´t - Lemao1981

1 Answers

0
votes

Looks like you arent applying any styling in your XML. If you check out the xml example in the Androidplot quickstart you'll notice it has a style applied like so:

<com.androidplot.xy.XYPlot
        style="@style/APDefacto.Dark"
        android:id="@+id/plot"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        ap:label="A Simple XY Plot"
        ap:rangeLabel="range"
        ap:domainLabel="domain"/>

The key attribute is style="@style/APDefacto.Dark", which basically applies a canned set of attrs to your plot to make it pretty. There's also a link in the doc to the full list of custom attrs if you prefer to come up with your own layout.

In any case applying the above style should solve the immediate problem you are having :-)