1

I have a graph in which i want to show Date-Time in the X Axis and some values in the Y Axis.

I am wondering how I can show the date and time on the X Axis. The Format in which i want to show is: dd/mm/yyyy hh:mm

My X Axis Data is :

Number[] xaxisSeries = {2407141120,2507141220,2607141640,2707141850,2807142027,2907142333};

plot.setDomainValueFormat(new SimpleDateFormat("dd/mm/yy hh:mm"));

But its not showing the correct values.

Please help me how should i show the Date-Time on my X Axis of the Graph

Korem
  • 11,383
  • 7
  • 55
  • 72
Kishan
  • 231
  • 1
  • 11

2 Answers2

1

Here's what worked for me, based on this example. In my case, I wanted to show time only, and the x values were millis since the epoch.

mGraphView.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM)
        .setFormat(new Format() {
            private final DateFormat dateFormat = DateFormat.getTimeInstance();

            @Override
            public StringBuffer format(Object obj,
                                       @NonNull StringBuffer toAppendTo,
                                       @NonNull FieldPosition pos) {
                Number timestamp = (Number) obj;
                return dateFormat.format(timestamp, toAppendTo, pos);
            }

            @Override
            public Object parseObject(String source, @NonNull ParsePosition pos) {
                return null;
            }
        });
Jon
  • 9,156
  • 9
  • 56
  • 73
0

There's a tutorial on androidplot.com that describes the process. Additionally, here's a similar question which includes another example of how it's done.

Community
  • 1
  • 1
Nick
  • 8,181
  • 4
  • 38
  • 63