frappe / insights

Open source analytics / business intelligence tool (BI)
https://frappe.io/insights
GNU Affero General Public License v3.0
368 stars 173 forks source link

Data points in charts with more than 1 dimension along x-axis attributed incorrectly when implicit 0-value data points exist #236

Closed mhobe closed 3 months ago

mhobe commented 4 months ago

Issue description

When

then

Steps to reproduce

  1. Use the following query to have a data set:

    SELECT 1 AS COUNT,
       'Apple' AS fruit,
       'Monday' AS day
    UNION ALL SELECT 3 AS COUNT,
       'Apple' AS fruit,
       'Tuesday' AS day
    UNION ALL SELECT 3 AS COUNT,
       'Orange' AS fruit,
       'Tuesday' AS day
  2. Create a bar chart for this data set with

    • day and fruit on its x-axis
    • count on its y-axis

Expected results

The expectation is clear: There should be

Actual results

Bildschirmfoto 2024-03-19 um 12 58 56

There are:

It seems that the framework just starts painting the data points starting at the earliest opportunity possible

Workaround

This issue can be worked around by adjusting the query to artificially introduce data points with value 0 in all places where there is an implicit 0 value, where possible. This however makes queries more complex and may not work in all cases.

For the example above this means:

SELECT 1 AS COUNT,
       'Apple' AS fruit,
       'Monday' AS day
UNION ALL SELECT 0 AS COUNT,
       'Orange' AS fruit,
       'Monday' AS day
UNION ALL SELECT 3 AS COUNT,
       'Apple' AS fruit,
       'Tuesday' AS day
UNION ALL SELECT 3 AS COUNT,
       'Orange' AS fruit,
       'Tuesday' AS day

would not exhibit the issue:

Bildschirmfoto 2024-03-19 um 13 00 38