elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.72k stars 8.14k forks source link

[ES|QL] No data displays in ES|QL charts when user switches from table to a bar chart #184744

Open bhavyarm opened 3 months ago

bhavyarm commented 3 months ago

Kibana version: 8.14.0 BC7

Browser version: chrome latest

Browser OS version: OS X

Original install method (e.g. download page, yum, from source, etc.): from staging

Describe the bug: If user switches from table to one of the bar charts on Create ES|QL visualization on a simple query like from _kibana_sample_datalogs | limit 1000, Kibana displays empty panel.

Steps to reproduce:

  1. Go to dashboard -> edit-> add es|ql panel
  2. ES|QL panels gets added with sample logs data table
  3. Edit the query to kibana_sample_data_logs | limit 1000 and run it - make sure the table gets updated
  4. Change the chart type to vertical in bar charts
  5. Kibana displays xy chart but no bars on it
  6. Switch the chart type to a non -bar type chart like something from proportion
  7. Data gets displayed

Screenshots (if relevant):

https://github.com/elastic/kibana/assets/7074629/6f68bf16-8711-4a43-8492-7e225ac0faa2

elasticmachine commented 3 months ago

Pinging @elastic/kibana-visualizations (Team:Visualizations)

elasticmachine commented 3 months ago

Pinging @elastic/kibana-esql (Team:ESQL)

stratoula commented 3 months ago

This is not a bug although I do understand the confusion. If you see what is going on it adds the @timestamp in the horizontal axis but it the raw value (no date_truck or bucket used) so EC do not render the bars correectly

image

@nickofthyme maybe you can explain why this happens. I think a warning in ase of raw timestamps is a good idea. We are already exploring this idea here https://github.com/elastic/kibana/issues/184205

Not sure if we need 2 issues to track this but I will let this to the viz team to decide

markov00 commented 3 months ago

@stratoula I believe this error on rendering is related to the fact that the @timestamp column seems not typed as date in the lens configuration. Can you please check if is possible to pass that parameter when clear column type is available? In this case, it seems that we are interpreting the timestamp as number (the axis shown is a numeric one).

The other problem, as linked by Stratoula relates to the fact that, to render bars we need to understand what is the bar width. We internally compute it as the minimum distance between consecutive time buckets (to avoid overlaps) but in this case it seems that the bar width is too small to be even visible.

stratoula commented 3 months ago

Interesting. Have you checked that or you are assuming from seeing the chart?

stratoula commented 3 months ago

@markov00 no, it remains a date field, something else is going wrong here. I guess it what I mention above but is better to check it too. But the field type is correct, I checked

markov00 commented 3 months ago

oh strange, so there is something else wrong because the axis style is definitely wrong

stratoula commented 3 months ago

It tries to render dates though

image
dej611 commented 3 months ago

From my tests the bug affects only non-stacked versions of the bar chart. Debugging the state of the component in the video, it seems that this check is failing: https://github.com/elastic/kibana/blob/ab6ecdb3a5f6ec1df45668982987cdd236441563/src/plugins/chart_expressions/expression_xy/public/components/xy_chart.tsx#L672-L675

So the new time axis mode is not enabled, leaving to "simple" dates to render on the X-axis: https://github.com/elastic/kibana/blob/ab6ecdb3a5f6ec1df45668982987cdd236441563/src/plugins/chart_expressions/expression_xy/public/components/xy_chart.tsx#L677-L678

dej611 commented 3 months ago

The root problem is this check: https://github.com/elastic/kibana/blob/ab6ecdb3a5f6ec1df45668982987cdd236441563/src/plugins/chart_expressions/expression_xy/public/components/xy_chart.tsx#L396-L401

When transitioning from table to Vertical Bar a breakdown dimension is automatically added to the Lens configuration, and that disables the new time axis. It's the equivalent for form-based configuration, the granularity of the date histogram here makes it just worse, where a bar is less than a pixel. Switching to stacked Vertical bar makes the bars appear again.

stratoula commented 3 months ago

@dej611 well done 👏 So this happens in DSL charts too, correct?

dej611 commented 3 months ago

Yes, I can replicate the same behaviour with DSL charts as well. It's just that a bucket in DSL cannot be 1ms, so it does not look that bad. Here's the smaller I could get for DSL:

Screenshot 2024-06-05 at 18 01 50
markov00 commented 3 months ago

I believe with a timestamp and a breakdown by a bar chart should always be shown as stacked bar, where instead a line/area chart can also be non-stacked by default.

stratoula commented 3 months ago

We never suggest it, Bhavya selected it from the chart switcher here

markov00 commented 3 months ago

I've created https://github.com/elastic/elastic-charts/issues/2461 to handle that on chart side by rendering at least 1px wide bars