The dates on the graph are sorted only by days and not months.

20 views
Skip to first unread message

arik...@gmail.com

unread,
Sep 3, 2017, 11:05:21 AM9/3/17
to SlamData-User

As you can see in the picture attached, I can't sort the months, only the days are sorted in the X axis.
Sort By doesn't help.

Thank you very much for your help!
Arik.

 
SELECT meals.bitesChosen,
    TO_STRING(DATE_PART("day", meals.StartTime)) || "." ||  TO_STRING(DATE_PART("month", meals.StartTime)) AS startDate,
    meals.StartTime,
   ((meals.EndTime - meals.StartTime)/1000)/60 AS Duration,
 CASE
    WHEN DATE_PART("hour",meals.StartTime) < 03 THEN "Night"
   WHEN DATE_PART("hour",meals.StartTime) < 10 THEN "Morning"
   WHEN DATE_PART("hour",meals.StartTime) < 14 THEN "Noon"
   WHEN DATE_PART("hour",meals.StartTime) < 18 THEN "Evning"
   WHEN DATE_PART("hour",meals.StartTime) < 25 THEN "Night"
   END
   AS partOfDay
FROM `/mealT` AS meals
INNER JOIN `/_User` AS users
   ON meals.userID = users._id
WHERE users.Name = :patient
    AND meals.StartTime >= :From
    AND meals.StartTime <= :To
   AND meals.isRemoved <> true

do...@slamdata.com

unread,
Sep 5, 2017, 11:03:26 AM9/5/17
to SlamData-User, arik...@gmail.com
Arik, you have changed the date to a string in the format of day.month. When using this value as the dimension, the charting library currently converts this value to decimal and this is why the values are plotted as they are. All dimensions are sorted in order from smallest to largest based on data type. What you are seeing is correct behavior.

Why are you converting the value to the format you are? If you want the chart to be sorted based on date, you can try the following for line 2:

SUBSTRING(TO_STRING(meals.StartTime), 0, 10) AS startDate,

This will give you only the date portion of your timestamp and the x-axis will be properly sorted by date.
Reply all
Reply to author
Forward
0 new messages