GitHub user dosubot[bot] added a comment to the discussion: Annotation cannot
be updated synchronously with filter changes.
<!-- Answer -->
There isn’t a built-in way in Superset to include annotation logic directly in
the main chart query, but you can achieve synchronous updates by merging your
annotation/event data with your main chart data in a single SQL query. For
example, you can use a `UNION ALL` or a `LEFT JOIN` to combine your main data
and annotation events, and add a column to distinguish between them (like
`series_type = 'main'` or `'event'`). Here’s a simplified example:
```sql
SELECT
date,
value,
'main' AS series_type
FROM main_table
WHERE {{ filter_condition }}
UNION ALL
SELECT
event_date AS date,
NULL AS value,
'event' AS series_type
FROM annotation_table
WHERE {{ filter_condition }}
```
Then, in Superset, plot both series on the same line chart (or Mixed Chart)
using the `series_type` column to split the lines or markers. This way, both
your main data and annotation events will update together with filters, since
they’re fetched in the same query and subject to the same filter propagation.
This approach works best for time series and line charts that support multiple
series. You may need to adjust your chart configuration to display the
annotation series as markers or lines, and style them differently for clarity.
Be aware that this method can increase query complexity and may not be ideal
for very large datasets or all chart types.
There’s no official example in the Superset docs, but this pattern is a common
workaround and is discussed in community threads as a way to keep reference
lines or events in sync with chart data
[[source]](https://github.com/apache/superset/issues/35856). The Superset
codebase also shows that annotation data is often merged into the main chart
data array before rendering, which is similar in spirit to this approach
[[source]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js#L728-L1023).
Let me know if you want a more detailed SQL example or help configuring the
chart!
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/7465c461-efc2-4e14-b5e5-d051ed12507a?feedback_type=other)</sup>
[](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=There%20isn%E2%80%99t%20a%20built-in%20way%20in%20Superset%20to%20include%20annotation%20logic%20directly%20in%20the%20main%20chart%20query%2C%20but%20you%20can%20achieve%20synchronous%20updates%20by%20merging%20your%20annotation/event%20data%20with%20your%20main%20chart%20data%20in%20a%20single%20SQL%20query.%20For%20example%2C%20you%20can%20use%20a%20%60UNION%20ALL%60%20or%20a%20%60LEFT%20JOIN%60%20to%20combine%20your%20main%20data%20and%20annotation%20events%2C%20and%20add%20a%20column%20to%20distinguish%20between%20them%20%28like%20%60series_type%20%3D%20%27main%27%60%20or%20%60%27event%27%60%29.%20Here%E2%80%99s%20a%20simplified%20example%3A%0A%0A%60%60%60sql%0ASELECT%0A%20%20date%2C%0A%20%20value%2C%0A%20%20%27main%27%20AS%20series_type%0AFROM%2
0main_table%0AWHERE%20%7B%7B%20filter_condition%20%7D%7D%0A%0AUNION%20ALL%0A%0ASELECT%0A%20%20event_date%20AS%20date%2C%0A%20%20NULL%20AS%20value%2C%0A%20%20%27event%27%20AS%20series_type%0AFROM%20annotation_table%0AWHERE%20%7B%7B%20filter_condition%20%7D%7D%0A%60%60%60%0A%0AThen%2C%20in%20Superset%2C%20plot%20both%20series%20on%20the%20same%20line%20chart%20%28or%20Mixed%20Chart%29%20using%20the%20%60series_type%60%20column%20to%20split%20the%20lines%20or%20markers.%20This%20way%2C%20both%20your%20main%20data%20and%20annotation%20events%20will%20update%20together%20with%20filters%2C%20since%20they%E2%80%99re%20fetched%20in%20the%20same%20query%20and%20subject%20to%20the%20same%20filter%20propagation.%0A%0AThis%20approach%20works%20best%20for%20time%20series%20and%20line%20charts%20that%20support%20multiple%20series.%20You%20may%20need%20to%20adjust%20your%20chart%20configuration%20to%20display%20the%20annotation%20series%20as%20markers%20or%20lines%2C%20and%20style%20them%20differe
ntly%20for%20clarity.%20Be%20aware%20that%20this%20method%20can%20increase%20query%20complexity%20and%20may%20not%20be%20ideal%20for%20very%20large%20datasets%20or%20all%20chart%20types.%0A%0AThere%E2%80%99s%20no%20official%20example%20in%20the%20Superset%20docs%2C%20but%20this%20pattern%20is%20a%20common%20workaround%20and%20is%20discussed%20in%20community%20threads%20as%20a%20way%20to%20keep%20reference%20lines%20or%20events%20in%20sync%20with%20chart%20data%20%5B%5Bsource%5D%5D%28https%3A//github.com/apache/superset/issues/35856%29.%20The%20Superset%20codebase%20also%20shows%20that%20annotation%20data%20is%20often%20merged%20into%20the%20main%20chart%20data%20array%20before%20rendering%2C%20which%20is%20similar%20in%20spirit%20to%20this%20approach%20%5B%5Bsource%5D%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/plugins/legacy-preset-chart-nvd3/src/NVD3Vis.js%23L728-L1023%29.%0A%0ALet%20me%20know%20if%20you%20want%20a%20mo
re%20detailed%20SQL%20example%20or%20help%20configuring%20the%20chart%21) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/36830)
GitHub link:
https://github.com/apache/superset/discussions/44408#discussioncomment-18489618
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]