For a while now I've been using a flatten transform to move data from a columnar data frame to a Vega Lite spec, and wonder if it's the source of a recent problem I've encountered with a time series. The time series spec is in a gist on the vega editor, along with a similar pattern plotting sin and cos that uses flatten without a problem.
As near as I can tell, the spx time series should work with this transform, and it does work if I flatten the data myself. I'm out of ideas; maybe there's something odd with flatten and date/times? I've tried every combination of type specification, timeUnit, etc., I can think of but nothing seems to work.
Can anyone spot an error in the spx time series gist?
For some reason, your dates are not getting parsed properly. It may be a bug but you can easily workaround it by using a calculate to convert your date to a proper date.
Editor
{
"transform": [
{"flatten": ["spxdate", "open", "high", "low", "close"]},
{"calculate": "toDate(datum.spxdate)", "as": "new"}
],
"data": {
"values": {
"spxdate": [
"1990-01-02",
"1990-01-03",
"1990-01-04",
"1990-01-05",
"1990-01-08",
"1990-01-09",
"1990-01-10",
"1990-01-11",
"1990-01-12",
"1990-01-15",
"1990-01-16",
"1990-01-17",
"1990-01-18",
"1990-01-19",
"1990-01-22",
"1990-01-23",
"1990-01-24",
"1990-01-25",
"1990-01-26",
"1990-01-29",
"1990-01-30",
"1990-01-31",
"1990-02-01",
"1990-02-02",
"1990-02-05",
"1990-02-06",
"1990-02-07",
"1990-02-08",
"1990-02-09",
"1990-02-12",
"1990-02-13",
"1990-02-14",
"1990-02-15",
"1990-02-16",
"1990-02-20",
"1990-02-21",
"1990-02-22",
"1990-02-23",
"1990-02-26",
"1990-02-27",
"1990-02-28",
"1990-03-01",
"1990-03-02",
"1990-03-05",
"1990-03-06",
"1990-03-07",
"1990-03-08",
"1990-03-09",
"1990-03-12",
"1990-03-13",
"1990-03-14",
"1990-03-15",
"1990-03-16",
"1990-03-19",
"1990-03-20",
"1990-03-21",
"1990-03-22",
"1990-03-23",
"1990-03-26",
"1990-03-27",
"1990-03-28",
"1990-03-29",
"1990-03-30",
"1990-04-02",
"1990-04-03",
"1990-04-04",
"1990-04-05",
"1990-04-06",
"1990-04-09",
"1990-04-10",
"1990-04-11",
"1990-04-12",
"1990-04-16",
"1990-04-17",
"1990-04-18",
"1990-04-19",
"1990-04-20",
"1990-04-23",
"1990-04-24",
"1990-04-25",
"1990-04-26",
"1990-04-27",
"1990-04-30",
"1990-05-01",
"1990-05-02",
"1990-05-03",
"1990-05-04",
"1990-05-07",
"1990-05-08",
"1990-05-09",
"1990-05-10",
"1990-05-11",
"1990-05-14",
"1990-05-15",
"1990-05-16",
"1990-05-17",
"1990-05-18",
"1990-05-21",
"1990-05-22",
"1990-05-23"
],
"open": [
353.3999938964844,
359.69000244140625,
358.760009765625,
355.6700134277344,
352.20001220703125,
353.8299865722656,
349.6199951171875,
347.30999755859375,
348.5299987792969,
339.92999267578125,
337,
340.7699890136719,
337.3999938964844,
338.19000244140625,
339.1400146484375,
330.3800048828125,
331.6099853515625,
330.260009765625,
326.0899963378906,
325.79998779296875,
325.20001220703125,
322.9800109863281,
329.0799865722656,
328.7900085449219,
330.9200134277344,
331.8500061035156,
329.6600036621094,
333.75,
333.0199890136719,
333.6199951171875,
330.0799865722656,
331.0199890136719,
332.010009765625,
334.8900146484375,
332.7200012207031,
327.9100036621094,
327.6700134277344,
325.70001220703125,
324.1600036621094,
328.67999267578125,
330.260009765625,
331.8900146484375,
332.739990234375,
335.5400085449219,
333.739990234375,
337.92999267578125,
336.95001220703125,
340.1199951171875,
337.92999267578125,
338.6700134277344,
336,
336.8699951171875,
338.07000732421875,
341.9100036621094,
343.5299987792969,
341.57000732421875,
339.739990234375,
335.69000244140625,
337.2200012207031,
337.6300048828125,
341.5,
342,
340.7900085449219,
339.94000244140625,
338.70001220703125,
343.6400146484375,
341.0899963378906,
340.7300109863281,
340.0799865722656,
341.3699951171875,
342.07000732421875,
341.9200134277344,
344.3399963378906,
344.739990234375,
344.67999267578125,
340.7200012207031,
338.0899963378906,
335.1199951171875,
331.04998779296875,
330.3599853515625,
332.0299987792969,
332.9200134277344,
329.1099853515625,
330.79998779296875,
332.25,
334.4800109863281,
335.5799865722656,
338.3900146484375,
340.5299987792969,
342.010009765625,
342.8699951171875,
343.82000732421875,
352,
354.75,
354.2699890136719,
354,
354.4700012207031,
354.6400146484375,
358,
358.42999267578125
],
"high": [
359.69000244140625,
360.5899963378906,
358.760009765625,
355.6700134277344,
354.239990234375,
354.1700134277344,
349.6199951171875,
350.1400146484375,
348.5299987792969,
339.94000244140625,
340.75,
342.010009765625,
338.3800048828125,
340.4800109863281,
339.9599914550781,
332.760009765625,
331.7099914550781,
332.3299865722656,
328.5799865722656,
327.30999755859375,
325.7300109863281,
329.0799865722656,
329.8599853515625,
332.1000061035156,
332.1600036621094,
331.8599853515625,
333.760009765625,
336.0899963378906,
334.6000061035156,
333.6199951171875,
331.6099853515625,
333.20001220703125,
335.2099914550781,
335.6400146484375,
332.7200012207031,
328.1700134277344,
330.9800109863281,
326.1499938964844,
328.6700134277344,
331.94000244140625,
333.4800109863281,
334.3999938964844,
335.5400085449219,
336.3800048828125,
337.92999267578125,
338.8399963378906,
340.6600036621094,
340.2699890136719,
339.0799865722656,
338.6700134277344,
337.6300048828125,
338.9100036621094,
341.9100036621094,
343.760009765625,
344.489990234375,
342.3399963378906,
339.7699890136719,
337.5799865722656,
339.739990234375,
341.5,
342.5799865722656,
342.07000732421875,
341.4100036621094,
339.94000244140625,
343.760009765625,
344.1199951171875,
342.8500061035156,
341.7300109863281,
341.8299865722656,
342.4100036621094,
343,
344.7900085449219,
347.29998779296875,
345.19000244140625,
345.3299865722656,
340.7200012207031,
338.5199890136719,
335.1199951171875,
332.9700012207031,
332.739990234375,
333.760009765625,
333.57000732421875,
331.30999755859375,
332.8299865722656,
334.4800109863281,
337.0199890136719,
338.4599914550781,
341.07000732421875,
342.0299987792969,
343.0799865722656,
344.9800109863281,
352.30999755859375,
358.4100036621094,
355.0899963378906,
354.67999267578125,
356.9200134277344,
354.6400146484375,
359.07000732421875,
360.5,
359.2900085449219
],
"low": [
351.9800109863281,
357.8900146484375,
352.8900146484375,
351.3500061035156,
350.5400085449219,
349.6099853515625,
344.32000732421875,
347.30999755859375,
339.489990234375,
336.57000732421875,
333.3699951171875,
336.260009765625,
333.9800109863281,
338.19000244140625,
330.2799987792969,
328.6700134277344,
324.1700134277344,
325.3299865722656,
321.44000244140625,
321.7900085449219,
319.8299865722656,
322.9800109863281,
327.760009765625,
328.0899963378906,
330.45001220703125,
328.20001220703125,
326.54998779296875,
332,
332.4100036621094,
329.9700012207031,
327.9200134277344,
330.6400146484375,
331.6099853515625,
332.4200134277344,
326.260009765625,
324.4700012207031,
325.70001220703125,
322.1000061035156,
323.9800109863281,
328.4700012207031,
330.1600036621094,
331.0799865722656,
332.7200012207031,
333.489990234375,
333.57000732421875,
336.3299865722656,
336.95001220703125,
336.8399963378906,
336.1400146484375,
335.3599853515625,
334.92999267578125,
336.8699951171875,
338.07000732421875,
339.1199951171875,
340.8699951171875,
339.55999755859375,
333.6199951171875,
335.69000244140625,
337.2200012207031,
337.0299987792969,
340.6000061035156,
339.7699890136719,
338.2099914550781,
336.3299865722656,
338.70001220703125,
340.3999938964844,
340.6300048828125,
338.94000244140625,
339.8800048828125,
340.6199951171875,
341.260009765625,
341.9100036621094,
344.1000061035156,
342.05999755859375,
340.1099853515625,
337.5899963378906,
333.4100036621094,
330.0899963378906,
329.7099914550781,
330.3599853515625,
330.6700134277344,
328.7099914550781,
327.760009765625,
330.79998779296875,
332.1499938964844,
334.4700012207031,
335.1700134277344,
338.1099853515625,
340.1700134277344,
340.8999938964844,
342.7699890136719,
343.82000732421875,
351.95001220703125,
352.8399963378906,
351.95001220703125,
354,
352.5199890136719,
353.7799987792969,
356.0899963378906,
356.989990234375
],
"close": [
359.69000244140625,
358.760009765625,
355.6700134277344,
352.20001220703125,
353.7900085449219,
349.6199951171875,
347.30999755859375,
348.5299987792969,
339.92999267578125,
337,
340.75,
337.3999938964844,
338.19000244140625,
339.1499938964844,
330.3800048828125,
331.6099853515625,
330.260009765625,
326.0799865722656,
325.79998779296875,
325.20001220703125,
322.9800109863281,
329.0799865722656,
328.7900085449219,
330.9200134277344,
331.8500061035156,
329.6600036621094,
333.75,
332.9599914550781,
333.6199951171875,
330.0799865722656,
331.0199890136719,
332.010009765625,
334.8900146484375,
332.7200012207031,
327.989990234375,
327.6700134277344,
325.70001220703125,
324.1499938964844,
328.6700134277344,
330.260009765625,
331.8900146484375,
332.739990234375,
335.5400085449219,
333.739990234375,
337.92999267578125,
336.95001220703125,
340.2699890136719,
337.92999267578125,
338.6700134277344,
336,
336.8699951171875,
338.07000732421875,
341.9100036621094,
343.5299987792969,
341.57000732421875,
339.739990234375,
335.69000244140625,
337.2200012207031,
337.6300048828125,
341.5,
342,
340.7900085449219,
339.94000244140625,
338.70001220703125,
343.6400146484375,
341.0899963378906,
340.7300109863281,
340.0799865722656,
341.3699951171875,
342.07000732421875,
341.9200134277344,
344.3399963378906,
344.739990234375,
344.67999267578125,
340.7200012207031,
338.0899963378906,
335.1199951171875,
331.04998779296875,
330.3599853515625,
332.0299987792969,
332.9200134277344,
329.1099853515625,
330.79998779296875,
332.25,
334.4800109863281,
335.57000732421875,
338.3900146484375,
340.5299987792969,
342.010009765625,
342.8599853515625,
343.82000732421875,
352,
354.75,
354.2799987792969,
354,
354.4700012207031,
354.6400146484375,
358,
358.42999267578125,
359.2900085449219
]
}
},
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"height": 400,
"width": 600,
"mark": "line",
"encoding": {
"x": {"field": "new", "type": "temporal", "timeUnit": "yearmonthdate"},
"y": {"field": "close", "type": "quantitative"}
}
}