title: Display dates in xAxis of an Android line graph
body: <p>I'm trying to display some values that I retrieve from my Firestore collection documents in two different line graphs. I use the jjoe64 library but my app crashes when I press the button to generate the graphs. <a href="https://i.stack.imgur.com/6hHGr.png" rel="nofollow noreferrer">Firestore database</a> Here's my fragment's code: </p>
  
  <pre><code>package com.example.drodo.diamondbeacons;
  
  
  import android.content.Context;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.inputmethod.InputMethodManager;
  import android.widget.Button;
  import android.widget.EditText;
  
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.firestore.DocumentSnapshot;
  import com.google.firebase.firestore.FirebaseFirestore;
  import com.google.firebase.firestore.QuerySnapshot;
  import com.jjoe64.graphview.GraphView;
  import com.jjoe64.graphview.LegendRenderer;
  import com.jjoe64.graphview.Viewport;
  import com.jjoe64.graphview.helper.StaticLabelsFormatter;
  import com.jjoe64.graphview.series.DataPoint;
  import com.jjoe64.graphview.series.LineGraphSeries;
  
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class TimelineFragment extends Fragment {
  
      private FirebaseFirestore firebaseFirestore;
      private FirebaseAuth firebaseAuth;
      private EditText regionText;
      private Button regionChooseBtn;
  
  
      public TimelineFragment() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_timeline, container, false);
  
          regionText = (EditText) view.findViewById(R.id.selectRegionText);
          regionChooseBtn = (Button) view.findViewById(R.id.chooseRegionBtn);
  
          firebaseAuth = FirebaseAuth.getInstance();
          firebaseFirestore = FirebaseFirestore.getInstance();
          regionChooseBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String select_text = regionText.getText().toString();
                  if (!select_text.isEmpty()) {
  
                      if(firebaseAuth.getCurrentUser() != null) {
  
                          firebaseFirestore.collection("PuckData").whereEqualTo("region", select_text)
                                  .get().addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
                              @Override
                              public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task) {
                                  if (task.isSuccessful()) {
                                      List&lt;String&gt; dates_list = new ArrayList&lt;&gt;();
                                      List&lt;Integer&gt; temperature_list = new ArrayList&lt;&gt;();
                                      List&lt;Integer&gt; light_list = new ArrayList&lt;&gt;();
                                      for (DocumentSnapshot document : task.getResult()) {
                                          int light = document.getLong("light").intValue();
                                          int temperature = document.getLong("temperature").intValue();
                                          Date date = document.getDate("timestamp");
                                          SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy-HH:mm");
                                          String stringDate = simpleDateFormat.format(date);
  
                                          temperature_list.add(temperature);
                                          light_list.add(light);
                                          dates_list.add(stringDate);
                                      }
  
                                      GraphView graph = view.findViewById(R.id.graph);
                                      LineGraphSeries&lt;DataPoint&gt; series = new LineGraphSeries&lt;&gt;(generateLightList(dates_list, light_list));
                                      graph.addSeries(series);
                                      Log.d("LIST", "DATES: " + dates_list.toString());
                                      Log.d("LIST", "TEMPS: " + temperature_list.toString());
                                      Log.d("LIST", "LIGHTS: " + light_list.toString());
                                  } else {
                                      Log.d("PUCK", "Error getting documents: ", task.getException());
                                  }
                              }
                          });
  
                      }
                  }
  
                  regionText.setText("");
  
                  final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                  imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
              }
          });
          return view;
      }
  
      private DataPoint[] generateLightList(List&lt;String&gt; dateList, List&lt;Integer&gt; lightList) {
          DataPoint[] values = new DataPoint[dateList.size()];
          for (int i = 0; i &lt; dateList.size(); i++) {
              DataPoint v = new DataPoint(Double.parseDouble(dateList.get(i)), lightList.get(i));
              values[i] = v;
          }
          return values;
      }
  
      private DataPoint[] generateTemperatureList(List&lt;String&gt; dateList, List&lt;Integer&gt; temperatureList) {
          DataPoint[] values = new DataPoint[dateList.size()];
          for (int i = 0; i &lt; dateList.size(); i++) {
              DataPoint v = new DataPoint(Double.parseDouble(dateList.get(i)), temperatureList.get(i));
              values[i] = v;
          }
          return values;
      }
  
  }
  </code></pre>
  
  <p>This is my model PuckData class:</p>
  
  <pre><code>package com.example.drodo.diamondbeacons.model;
  
  import com.google.firebase.firestore.ServerTimestamp;
  
  import java.util.Date;
  /**
   * Created by drodo on 25-Mar-18.
   */
  
  public class PuckData {
  
      public int light, temperature;
      public double battery;
      public Date timestamp;
  
  
      public PuckData() {}
  
      public PuckData(int light, int temperature, double battery, Date timestamp) {
          this.light = light;
          this.temperature = temperature;
          this.battery = battery;
          this.timestamp = timestamp;
      }
  
      public double getLight() {
          return light;
      }
  
      public void setLight(int light) {
          this.light = light;
      }
  
      public double getTemperature() {
          return temperature;
      }
  
      public void setTemperature(int temperature) {
          this.temperature = temperature;
      }
  
      public double getBattery() {
          return battery;
      }
  
      public void setBattery(double battery) {
          this.battery = battery;
      }
  
      public Date getTimestamp() {
          return timestamp;
      }
  
      public void setTimestamp(Date timestamp) {
          this.timestamp = timestamp;
      }
  
  }
  </code></pre>
  
  <p>I want to to display in the first graph xAxis(dates) and yAxis(light) and dates-temperature in the other graph. My app crashes when I press the button in order to pick only the region that the user typed in the edit text and this is what I get: </p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: For input string: "07/07/18-04:50"
            at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306)
            at java.lang.Double.parseDouble(Double.java:547)
            at com.example.drodo.diamondbeacons.TimelineFragment.generateLightList(TimelineFragment.java:118)</p>
  </blockquote>