Page MenuHomePhabricator

Charts mix up data when data points don't match in time
Open, LowPublicBUG REPORT

Assigned To
None
Authored By
Theklan
Dec 22 2025, 9:57 AM
Referenced Files
F71231782: image.png
Dec 24 2025, 9:56 AM
F71196663: irudia.png
Dec 22 2025, 9:57 AM
F71196656: irudia.png
Dec 22 2025, 9:57 AM
F71196652: irudia.png
Dec 22 2025, 9:57 AM
F71196636: irudia.png
Dec 22 2025, 9:57 AM
F71196632: irudia.png
Dec 22 2025, 9:57 AM
F71196627: irudia.png
Dec 22 2025, 9:57 AM
F71196622: irudia.png
Dec 22 2025, 9:57 AM

Description

Steps to replicate the issue (include links if applicable):

  • When using a chart with Wikidata access, the data is mixed if all the items don't have the same points in time (P585)
  • It can be tested on wikis with Wikidata data access for Charts

What happens?: If three different entities are given, for example Q744893, Q1242393 and Q747628 and population is plotted, Q1242393 has less data points that the others, because is a newer entity. The individual graphs are ok, but if the three lines are present they mix the data:

Individual one for Q744893 (wikicode used at euwiki: {{biztanleria grafiko automatikoa|item=Q744893}})

irudia.png (766×1 px, 64 KB)

If both Q744893 and Q1242393 are added, the graph is istill working ({{biztanleria grafiko automatikoa|item=Q744893,Q1242393}}):

irudia.png (756×1 px, 67 KB)

However, Q1242393 is a newer entity, so no population data exists before 1970. Then, when a third is added, data is mixed, adding to Q1242393 the data from Q1242393: ({{biztanleria grafiko automatikoa|item=Q744893,Q1242393,Q747628}})

irudia.png (761×1 px, 77 KB)

However, if the order is changed, to present the one with fewer data points the last, then the lines are rendered correctly: {{biztanleria grafiko automatikoa|item=Q744893,Q747628,Q1242393}}

irudia.png (753×1 px, 75 KB)

The same issue happens if the data is very different, like comparing London (Q84) and New York (Q84):

irudia.png (759×1 px, 99 KB)

If a third one is added (Barcelona, Q1492), then the result is even more wild:

irudia.png (780×1 px, 170 KB)

And it changes if we reverse the order of the items:

irudia.png (759×1 px, 170 KB)

What should have happened instead?: The lines should be consistent.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

It's not a bug in Charts extension, it's a bug in the Graphs module on Commons. I've reported it about a month ago.

The problem is that Lua doesn't store a nil value in its array. Therefore, during the transformation from Lua arrays to JSON tables, it moves a value from the next cell after nil to the cell with a nil value (or from y2 to y if we talk about Module:Graph:Chart). It would be useful if the Lua transformer to JSON had a magic word to denote that a cell has a null value. For more information, see https://www.mediawiki.org/wiki/Extension:Chart/Transforms#Null/nil . As for now, I think that the only way to fix, is to transform nil values to 0 or "", but this also significantly distorts the charts with big drops to the bottom if the line chart has thousands on its y-axis.

This bug is related to T388434. Therefore, I'm also adding JsonConfig to this task.

If I understand the issue correctly, adding a 0 can't be the solution.

Let's think on two lines, the first one has value A=6 and C=8. The second one has values A=9, B=10 and C=7. Adding a B=0 to the first one would change the most logical value for that point, something around 7. The graph needs to know that there is no point at B, it should go directly from A to C, while showing A, B and C for the second line. I understand that a null value is the best solution.

If I understand the issue correctly, adding a 0 can't be the solution.

Let's think on two lines, the first one has value A=6 and C=8. The second one has values A=9, B=10 and C=7. Adding a B=0 to the first one would change the most logical value for that point, something around 7. The graph needs to know that there is no point at B, it should go directly from A to C, while showing A, B and C for the second line. I understand that a null value is the best solution.

I agree with that. However, as for now, charts with null values don't make a continuous line. Here is a chart with a tab (source: https://commons.wikimedia.org/wiki/Data:Competitions:Views_from_Ukraine.tab ; unused tab that I used for testing behavior with null cell) with a null value in the blue line:

image.png (494×749 px, 24 KB)
.

Good example. Then null is not a solution. It solves part of the issue (taking fake numbers) but the line should be continous. I assume that each line should be taken as completely independent.

If we're sure the bug is in https://commons.wikimedia.org/wiki/Module:Graph:Chart , and not in https://www.mediawiki.org/wiki/Extension:Chart or https://www.mediawiki.org/wiki/Extension:JsonConfig , then this ticket may be filed in the wrong place and we might want to close it as invalid.

If we're sure the bug is in https://commons.wikimedia.org/wiki/Module:Graph:Chart , and not in https://www.mediawiki.org/wiki/Extension:Chart or https://www.mediawiki.org/wiki/Extension:JsonConfig , then this ticket may be filed in the wrong place and we might want to close it as invalid.

I think it can be reformatted as a feature request with a text like: Create a way to explicitly mark a cell as null in a Lua array that will be transformed by JSON config to a null cell in a JSON table. Because, as for now, I haven't found a way to mark a certain cell as null in Lua that would transform to null in JSON table.

I see even two feature requests here -- 1) adding support in Extension:Chart for null or NaN values -- making continuous lines by ignoring them, 2) adding support in Extension:JsonConfig for producing null values from Lua (and obviously 3) patching Module:Graph:Chart in the required way).