0
votes

I am trying to create a custom XYPlot with Androidplot but can't seem to fully configure it.

This is my code:

    XYSeries series = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(times), "Time on level");

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter formatter = new LineAndPointFormatter(Color.rgb(0, 100, 0), Color.rgb(0, 100, 0), null, new PointLabelFormatter(Color.BLUE));
    totalTimePlot.setRangeValueFormat(new DecimalFormat("#.#"));

    totalTimePlot.setGridPadding(0, 0, 0, 200);
    totalTimePlot.setBackgroundColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    totalTimePlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    totalTimePlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    totalTimePlot.setTicksPerDomainLabel(1);
    totalTimePlot.setRangeStepValue(10);
    totalTimePlot.getGraphWidget().setDomainLabelOrientation(-90);
    totalTimePlot.setMarkupEnabled(false);
    totalTimePlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);

    totalTimePlot.setDomainValueFormat(new Format() {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE(MM.dd)-HH:mm:ss");

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

        @Override
        public Object parseObject(String string, ParsePosition position) {
            return null;
        }
    });

    totalTimePlot.getGraphWidget().setPaddingLeft(4);
    totalTimePlot.addSeries(series, formatter);

And this is the end result:

enter image description here

As you can see this is very ugly. Can you help me at least configure it so that the Range labels are displayed. I would also like to know how to make the background white as well as have the first and last "ticks" visible.

Thank you.

EDIT:

I managed to include the first and last value by setting the boundaries. But the other problems remain.

1

1 Answers

0
votes

Agreed it's pretty ugly :-) It would be easier to give you suggestions if you list a few specific items you'd like to improve. Having said that, here's a few things I would start with:

  • Use the DemoApp's SimpleXYPlotActivity xml style as a starting point. This should fix your margin issues and improve the overall appearance.
  • Simplify your date/time format for your domain labels. Maybe something like day/month hour:minute. I don't know your exact use case so maybe you require the format you're using.
  • Get rid of the dark background that frames your plot.
  • Consider using the CatmullRomInterpolator to draw a smooth line.