• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Axis value in GraphView

I
faced with the following problem: I need to build a graph. One of the axises is usual number and the second is date, which is kept in GregorianCalendar object. In fact, I need to add on this axis dates, for example 01.01.1000 and the distance between the dates should be proportional (for example 01.01.1000 and 02.01.1000 should be much closer to each other than 02.01.1000 and 03.03.1000). But I have no ideas how to do it. I had some thoughts about parsing this dates to string, but didn't invent anything further

Tried to do it in a such way:

Code:
createGraph.setOnClickListener(new View.OnClickListener() {
           [USER=1021285]@override[/USER]
           public void onClick(View v) {
               Log.d(LOG_TAG, "--- Rows in myTable: ---");
               SQLiteDatabase db = dbHelper.getWritableDatabase();
               Cursor cursor = db.query("myTable",null,null,null,null,null,null);
               ArrayList<Integer> pulses = new ArrayList<>();
               ArrayList<Calendar> dates = new ArrayList<>();
               if (cursor.moveToFirst()){
                   int idColIndex = cursor.getColumnIndex("id");
                   int idColPulse = cursor.getColumnIndex("pulse");
                   int dateColIndex = cursor.getColumnIndex("date");
                   int monthColIndex = cursor.getColumnIndex("month");
                   int yearColIndex = cursor.getColumnIndex("year");
                   do{
                       pulses.add(cursor.getInt(idColPulse));
                       dates.add(new GregorianCalendar(cursor.getInt(yearColIndex), cursor.getInt(monthColIndex), cursor.getInt(dateColIndex)));
                   }while (cursor.moveToNext());
                   cursor.close();
                   dbHelper.close();
               }
               DataPoint arr[] = new DataPoint[pulses.size()];
               for (int i = 0; i<pulses.size();i++){
                   arr = new DataPoint(dates.get(i), pulses.get(i));
               }
           }
       });

But there's no constructor for DataPoint with GregorianCalendar and int
 
Last edited by a moderator:
First thing is, decide on the date range. You can calculate that by finding the minimum and maximum values in your data set.
Then sort your data into date range order.
For each data point, convert the date to a day offset, based on the first (minimum) date.
Plot the day offset on your graph.
 
First thing is, decide on the date range. You can calculate that by finding the minimum and maximum values in your data set.
Then sort your data into date range order.
For each data point, convert the date to a day offset, based on the first (minimum) date.
Plot the day offset on your graph.

Sorry, I'm not from an English speaking country, that's why it's hard for me to understand the meaning of some words. For examle, what does it mean 'day offset'? The translator says that it's a synonim of a word 'displacement'. Is it right? I didn't understand a little bit this moment.
And what is about sorting dates, they're always kept sorted
 
Ok here's a simple example. Suppose I have the dates

1/10/2018
5/10/2018
29/10/2018

What we need to do, is convert each of those dates to a single numerical value.
So let's assign a value of '0' to the first of those dates.
The next date is 4 days later, so we give that a value of '4'.
The next date is 28 days later, so it gets a value of '28'.

So you can see that all of the dates have a value which is relative to the first one. That's why the dates have to be in order.

Once you calculated a value for all your dates, you can use these values as the date axis of your graph.
 
Ok here's a simple example. Suppose I have the dates

1/10/2018
5/10/2018
29/10/2018

What we need to do, is convert each of those dates to a single numerical value.
So let's assign a value of '0' to the first of those dates.
The next date is 4 days later, so we give that a value of '4'.
The next date is 28 days later, so it gets a value of '28'.

So you can see that all of the dates have a value which is relative to the first one. That's why the dates have to be in order.

Once you calculated a value for all your dates, you can use these values as the date axis of your graph.

Yes, you are right, but I still don't understand how to put it on graph. I can't put object here. The same with string. But I should put here 1/10/2018 for example. How can I put it?
 
Depends what graph library you're using. Have you looked at the documentation for it? Is there a user guide?
 
Back
Top Bottom