donderdag 12 november 2015

Mendix and the Simple Charts

I've been struggling a few hours with generating statistics and then looked forward to creating some bar charts and pie charts. It was supposed to be simple.

If you know what you are doing, then sure, it's simple enough :)

For the bar chart, just create some a table and some data for the X-axis and a label for the Y-axis and you're good to go.
For a pie chart, you need to create a separate table with a label and a value, then create a list of these name/value pair objects and commit. Put the label on the X-axis and the value on the Y-axis.

However, the implementation of the pie chart is not super (november 2015). In the Features tab selecting Show Legend and Show Hover have no effect. The only way to manipulate the Simple Chart is by using the Extra options field. You know, that one which says 'this property should be omitted'.

There is no error checking on this, so it's a matter of trying out the various options to see what works and what not.
When you do start on this, some pointers:



Example 1:
{
        series: {
            pie: {
                show: true,
                label: {
                  threshold: 0.02
                }
            }
        },
        legend: {
              show: 'true'
        }
}

This will show a legend.
It will show only labels on the pie chart for sections which are larger than 2%



Example 2:
{
        series: {
            pie: {
                show: true,
                combine: {
                    color: '#999',
                    threshold: 0.05,

                    label: 'different than the others'
                }

            }
        },
        legend: {
              show: 'true'
        }
}

This will do the same as example 1, but then instead of not showing a label on a section, instead it will combine all sections smaller than 5% into one big section 'Other'. If you also specify the label parameter as I did here in this example, it will change the caption of the other category into 'different than the others'.