Column chart with Microflow source gives error for x/y axis attributes
Short version: Why would the charts widget allow us to use a Microflow as a data source for a chart, but not let us define which attribute can be used for the x and y attributes? You get an error if you try to define which attributes are used for the axes. But you get an error if you leave it blank because it’s required. It’s a catch 22. If you can’t set the X and Y axes when using a microflow, that means you can’t even use a Microflow as a data source, so why give us the option at all if it doesn’t work? Someone please tell me I’m missing something important. Long version: I have a dashboard with lots of graphs and I’ve gotten familiar with them all. I wanted a stacked bar graph for managers to categorize their employees’ hours. Each manager will enter a record (row) into the entity (table) that contains a quarter they’re entering for (eg Q1), and three fields for the number of manhours spent on each category: Base, Innovation, Unplanned. So I managed to get a stacked graph with 3 series, 1 for each category and it aggregates the hours for each quarter. Each series I use one of three hours fields for the Y axis and the quarters are the X axis. So I get almost what I want below: It looks good but there’s a catch. I want the Y/vertical axis to show PERCENTAGES, not totals. There didn’t seem to be any out-of-the-box way to do this in the options, so I created a datasource that loops through each quarter, creating ONE record/object per quarter and inserts a number (0 to 100) to represent the percentage of that quarter’s whole. Each quarter’s record is added to a list of the exact same entity type that was originally used as the data source and returned by the microflow. Perfect, right? Wrong. I get this: After reading the documentation here (https://docs.mendix.com/refguide/charts-configuration), it explains under the x and Y axes “For data source Microflow, references are not supported”. So you can’t set the X/y axes with a microflow? But these are required. SO … is having a Microflow datasource a mistake by Mendix? Or is there something I’m not getting? WHen the message says “references” does it mean “associations”? Because, if so, that seems like a major flaw with no workaround.
After looking up “reference”, it looks like the fact that my entity has an association and one of the axes relies on this associated value is the problem. This seems like a massive problem. But… as a programmer, you accept you need a workaround at times. I did the following, which seems “dirty’ but it did the trick.
I copied the entity, replacing the association with a new string field. In my Microflow, when I built a list of objects, I built a list of these “cloned” objects based on the new entity and instead of storing the associated quarter, I just stored the string value of the associated entity. Then I returned a list of these objects of these “cloned” entity types. It did the trick. I lost all my sorting from the associated entity, but I’ll find a way to tweak that. Now I’ve got a clean, graph where all quarters are at 100%. Here is the result. I just thought I’d post my own answer in case anyone else came across this, or if anyone else has a better way to doing this: