We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.

How to Sort Bar Chart Items

Closed
Mariano asked on December 14, 2021

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"
countryOrder1
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

2 answers

Public
Vera Didenko Vera Didenko Flexmonster December 15, 2021

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:

  1. Providing a presorted data set to Flexmonster:

    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/.

  2. Sorting the members via the 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/.

  3. Specifying the order in the 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

Public
Mariano December 16, 2021

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