Question:
I want to display sorted data of an Analytics Querie in a bar chart. Why are the bars shown unsorted? (see figures below)
Answer:
The problem here is that the Id is always interpreted as a numeric value, even if you override axis data type with data type string in the Chart settings -> X-Axis. Therefore the bars aren't sorted by their y-value (which in this case is the alarm count), but by the ID number of the Alarms (which is chosen as X-Axis column).
To avoid this behaviour and to force the alarm IDs to be treated as strings we have to do a little trick. In the analytics querie we have used we will add a CalculatedColumn. In our function we will take our ID and add a special white character to this string. Now the ID can't be converted in a numeric value anymore, but we also can't see that there is any character added to the labels. The special character we have used is the Unicode Character 'HALFWIDTH HANGUL FILLER'.
You can copy it without the quotes from here: "ᅠ "
Or from this site: http://www.fileformat.info/info/unicode/char/ffa0/index.htm
In the chart settings we now have to choose our CalculatedColumn as X-Axis Column. Now the order of the bars is preserved and are sorted as desired.