Skip to content

Add Visualizations API examples to Lens chart pages#5645

Draft
florent-leborgne wants to merge 5 commits intoelastic:mainfrom
florent-leborgne:lens-api-chart-examples
Draft

Add Visualizations API examples to Lens chart pages#5645
florent-leborgne wants to merge 5 commits intoelastic:mainfrom
florent-leborgne:lens-api-chart-examples

Conversation

@florent-leborgne
Copy link
Member

@florent-leborgne florent-leborgne commented Mar 26, 2026

Summary

Add "Create this chart using the API" collapsible dropdowns to all 13 Lens chart type documentation pages plus an API intro section to the main Lens page. Each dropdown contains a cURL payload that recreates the described chart via POST /api/visualizations.

What is included

  • 50 inline API dropdowns after individual examples and advanced scenarios across all chart pages
  • Lens overview page (lens.md): New "Create visualizations with the API" section with links to stateful and serverless API docs
  • All sections gated with applies_to: stack: preview 9.4 / serverless: preview

Integration test results

50/50 payloads pass against a live Kibana 9.4 snapshot with all three sample datasets loaded. Every payload creates a visualization successfully and is cleaned up after testing.

Testing script: kibana:oas_docs/scripts/validate_viz_examples.js

Test plan

  • All 50 JSON payloads parse successfully
  • 50/50 payloads create visualizations against a live 9.4 snapshot
  • All created visualizations cleaned up after testing
  • Vale linting passes
  • Cross-check against final public API spec when available

@github-actions
Copy link
Contributor

github-actions bot commented Mar 26, 2026

Vale Linting Results

Summary: 1 suggestion found

💡 Suggestions (1)
File Line Rule Message
explore-analyze/visualize/lens.md 60 Elastic.WordChoice Consider using 'can, might' instead of 'may', unless the term is in the UI.

The Vale linter checks documentation changes against the Elastic Docs style guide.

To use Vale locally or report issues, refer to Elastic style guide for Vale.

Add "Create this chart using the API" collapsible dropdowns after each
individual example and advanced scenario across all 13 chart type pages.
Each dropdown contains a cURL payload that recreates the described chart
via POST /api/visualizations.

50 dropdowns total covering:
- 27 chart examples (matching UI-built configurations)
- 13 advanced scenarios (time shifts, reference lines, stacked bars, etc.)
- Multiple chart types per payload pattern

Also adds a Visualizations API intro section to the main Lens page with
links to both stateful and serverless API docs.

All sections gated with applies_to: stack: preview 9.4 / serverless: preview.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Switch from code block applies_to inside dropdowns to the
:applies_to: directive option syntax per docs-builder conventions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove bash-specific quote escaping from JSON payloads in cURL examples.
Single quotes inside JSON strings are valid and don't need escaping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes validated against a 9.4 snapshot with all sample datasets:
- Move dataset inside XY layers (area, bar, line charts)
- Fix field names: slice_by→group_by, x_axis→x, tags→tag_by, etc.
- Remove null values (API rejects nulls for optional fields)
- Fix split_metrics_by to be an array
- Fix other_bucket to use object format
- Fix filters operation structure in group_by
- Fix formula quoting (bare single quotes, no shell escaping)

39 of 50 payloads now pass integration tests. The 11 remaining
failures are all caused by the same runtime bug: the
minMaxAvgMedianStdDevMetricOperation discriminator doesn't resolve,
so operations like average/min/max fail validation. These payloads
are structurally correct per the spec and will work once the
discriminator bug is fixed. Tracked in VISUALIZATIONS_API_DISCREPANCIES.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Key fixes:
- metric charts: add type:primary/secondary, alignments, icon fields
- gauge charts: fix color step structure
- line charts: fix moving_average to use nested "of" field
- bar charts: fix reference line layer to use thresholds array
- tables: fix split_metrics_by to be array

All 50 payloads now create visualizations successfully against
a live Kibana 9.4 snapshot with sample data loaded.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant