Custom sorting from mongoDB query breaks after grouping fields

I needed to create custom sorting based on some rules, so my data looks logical, but I ran into issues, when there is no data for one of the groups which the x value is on.

In order to create my custom sorting I added a column weight, and calculated the values, but the order breaks after the mentioned problem.

I tried adding dummy data where a script creates documents with value of 0 for my y axis and it kind of worked.

Here is my chart, it looks really ugly without the order and is unusable

I also tried searching for solutions for such issue, but to no avail, are there other things I could try?

Here is, the order I want and this is achieved by removing the x values from the list where not all groups have data or when I have dummy data in place

Is there a better way to do this maybe through redash or mongo, any advice helps.

Maybe these are relevant?

I enabled stacking and excluded set missing values not to show up and got a lot better looking line chart

“The Treat missing/null values as 0” issue does not work for me by itself as well, so it could be relevant, but the order is still messed up, at least the chart looks bearable