I have two time series for example:
s1:
2017-01-06 18:39:30 100
2017-01-07 18:39:28 101
and
s2:
2017-01-07 18:00:00 90
2017-01-08 18:00:00 105
I want to plot these in a Chartjs chart, however it seems that Chartjs only takes one x-axis array (or label in Chartjs terminology).
So my question is what is the best way to plot both of these?
My approach was to write a function (in python, although the language doesn't really matter for this part) that iterates through both time series and creates 3 new arrays which is in the format apparently Chartjs needs based off the 1st example here: https://www.sitepoint.com/introduction-chart-js-2-0-six-examples/
The algorithm (in sudo code) goes like:
# inputs are initial time series s1 and s2
y1 = [] # to hold new s1 data values
y2 = [] # to hold new s2 data values
x = [] # to hold times
# iterate through longest series s1 or s2
if s1[idx].time > s2[idx].time
x.append(s1[idx].time)
y1.append(s1[idx].data)
# y2 appends the linear interpolation of
# of closest y2 points
if (s1[idx].time < s2[idx].time)
x.append(s2[idx].time)
# opposite of above. ie. swap y1<->y2, s1->s2
else # they have the same time
x.append(s1[idx].time)
y1.append(s1[idx].data)
y2.append(s2[idx].data)
There are a couple other conditional checks for when data runs out of the shorter series but that is the main logic. After which I have 3 arrays that I can now add to chart js via one time/label array/x-axis and two data arrays. However this seems WAY more complicated than it should be considering how common I assume this use case is. Any help or advice is greatly appreciated.