I want to display a user's entered information on a time series line graph. ChartJS seems to be a great free way to do this. It needs an array of dates, and an array of the values for those dates.
Say if the user asks for data between two dates, and grouped by the day.
In my database I have a table, and each row has a UNIX timestamp. I can easily call up data and group by a given day, e.g.
SELECT some_metric
FROM tbl_example
WHERE date BETWEEN [start_ts] AND [end_ts]
GROUP BY DAY(FROM_UNIXTIME(date))
I also have a function that can make an array of the days between two dates.
Now the problem is that users don't have data on certain days, so I'll need to amend the array that MySQL spits out so that some days have 0.
Apart from a horrid double nested foreach
cross-checking dates in either array is there an efficient way to fix gaps in data in MySQL or PHP?
Update: This seems like a possible solution for handling gaps in time series data on the JavaScript side.
Update: I came up with a relatively simple 20-line solution in PHP. It reformats the array of values that MySQL spits out and for each date does an if (isset(...))
check on that array and then adds 0 for that date.
It does the job for days so far but I'll have to delve a little deeper for it to work with weeks and months.