-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hmm, I can't tell for sure without seeing underlying data. I might start by looking at the logs for the generated queries and making sure nothing looks off and/or looking at the returned query results (inspectable via (For more detailed help in the future, please include a small dataset that replicates the issue!) |
Beta Was this translation helpful? Give feedback.
-
It appears the problem is due to repeated timestamp values. For a line mark this does not create a visible problem as the line segments are connected vertically. Area marks (which perform stacking by default) lead to displacements when given duplicate values. One solution is to pre-aggregate the data to suppress duplicates. For example, in a Mosaic YAML spec it might look something like this, when ignoring categories: data:
init: |
(SELECT 1843::DOUBLE AS "Amount", 'A' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 1937::DOUBLE AS "Amount", 'A' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 515::DOUBLE AS "Amount", 'B' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 2300::DOUBLE AS "Amount", 'D' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 798::DOUBLE AS "Amount", 'C' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 718::DOUBLE AS "Amount", 'C' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 5160::DOUBLE AS "Amount", 'C' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 1620::DOUBLE AS "Amount", 'A' AS "Category", '2013-09-22 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 2053::DOUBLE AS "Amount", 'A' AS "Category", '2013-09-24 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 2926::DOUBLE AS "Amount", 'A' AS "Category", '2013-09-29 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 165::DOUBLE AS "Amount", 'B' AS "Category", '2013-09-30 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 5034::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-01 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 690::DOUBLE AS "Amount", 'C' AS "Category", '2013-10-02 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 4216::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-07 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 6052::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-13 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 1094::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-13 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 2597::DOUBLE AS "Amount", 'C' AS "Category", '2013-10-13 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 6217::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-16 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 635::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-17 22:00:00+00'::TIMESTAMP AS "ts") UNION ALL
(SELECT 3083::DOUBLE AS "Amount", 'A' AS "Category", '2013-10-21 22:00:00+00'::TIMESTAMP AS "ts")
mydata: SELECT SUM(Amount) AS Amount, ts FROM init GROUP BY ts In addition, I recommend including more detail in your cumulative sum. To avoid unexpected errors, specify the y: { sum: Amount, order: ts, rows: [null, 0] } And if you want cumulative sums on a per-category basis, include the category column as y: { sum: Amount, partition: Category, order: ts, rows: [null, 0] } |
Beta Was this translation helpful? Give feedback.
Yes, the
areaY
mark is sensitive to the data sort order. One option is to query your data with a desired order. You should be able to indicate this via a markorder
option ("order": "k"
). Note that theareaY
mark will already sort along the x-axis for you.Sorting won't help with the sparse data issue, though. One option is to impute missing values for each timestamp you want to sample, though I don't think Observable Plot provides any support for this at the plotting level. You could do this in DuckDB using CTEs and appropriate joins, but it's a bit involved...