Hello,
i am trying to understand how to sort the items in a bar chart but i'm having no luck.
I have a report whose items have this structure:
{
Year: "2016"
country: "Austria"
countryOrder: 1
Amount: 1
}
And this is the structure of the report:
return {
dataSource: {
data: getData()
},
slice: {
rows: [
{
uniqueName: "country",
},
],
columns: [
{
uniqueName: "[Measures]",
},
],
measures: [
{
uniqueName: "Amount",
aggregation: "sum",
},
],
expands: {
expandAll: true,
},
drills: {
drillAll: true,
},
},
options: {
viewType: "charts",
grid: {
type: "classic",
showTotals: "off",
showGrandTotals: "rows",
},
},
};
}
I would like to order the items by "countryOrder" field, i tried with the custom sorting but i think that i cannot sort a field that is not in slice object.
Can you please help me?
Thank you
Hello, Mariano,
Thank you for reaching out to us and for providing a sample report configuration.
Although using another field from the data set to define the order isn't supported, Flexmonster offers other ways to sort a field. To sort members in a custom order, we recommend one of the following solutions:
You could provide Flexmonster with presorted data and set the corresponding field as unsorted
in the slice
via the sort
property. This way Flexmonster will preserve the order in which the members were loaded. Here is an example: https://jsfiddle.net/flexmonster/ohs0gxw2/.
sortingMethod()
API call:
With the sortingMethod()
API call, you could sort the members based on custom rules.
Please see the following JSFiddle: https://jsfiddle.net/flexmonster/w3r8fgsc/.
sortOrder
configuration property (for JSON
and CSV
data source types):
Also, you could provide the list of members in the order that you would like them to be displayed via the sortOrder
property in the slice
.
We have prepared an example for illustration: https://jsfiddle.net/flexmonster/wdm1gsf4/.
Please let us know if one of the suggested solutions works for your case.
Looking forward to your reply.
Kind regards,
Vera
Hello Vera,
thank you for your answer, I've been able to apply the sorting using the approach that you suggested.
This question is now closed