Dear visitor, despite the COVID-19 outbreak, our team continues operating at full speed.

Also, here is the form where you can apply for a special discount and we will contact you with possible options. Stay safe and continue achieving your business goals.

Fill the form
Get Free Trial
Get Free Trial

How can I change the sort order in charts

Answered
Silvan Spross asked on March 13, 2020

I create a Flexmonster with JSON data, like:

var pivot = new Flexmonster({
container: "pivot",
report: {
dataSource: {
dataSourceType: "json",
filename: "/api/v1/stats/"
}
},
reportcomplete: function() {
pivot.off("reportcomplete");
createChart();
}
})

And then I render a Highcharts Column-Chart like:

function createChart() {
var render = function(data) {
Highcharts.chart('pivot_chart', data);
}
pivot.highcharts.getData(
{
type: "column",
"slice": {
"rows": [
{
"uniqueName": "total_salary",
}
],
"columns": [
{
"uniqueName": "[Measures]"
},
{
"uniqueName": "status"
}
],
"measures": [
{
"uniqueName": "number_of_persons",
"aggregation": "sum"
}
]
}
},
render, // callbackHandler
render // updateHandler
);
}

My total_salary values look like: “< 30’000”, “30’000 – 40’000”, “60’000 – 70’000” but they are not ordered like this in the chart. I tried to set the sortOrder like:

"rows": [
{
"uniqueName": "total_salary",
"sortOrder": ["< 30'000", "30'000 - 40'000", "60'000 - 70'000"]
}
],

But it’s not working. Can somebody explain me how to do this? Thanks a lot!

1 answer

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster March 16, 2020

Hi Silvan,
 
Thank you for posting your question!
 
In order for the column sorting to work as expected, we would suggest defining the sorting order in the slice of the pivot table object instead of the `pivot.highcharts.getData` method. This way the order of fields displayed by Highcharts instance will be derived from that of the pivot table instance.
 
We’ve prepared a quick JSFiddle example to demonstrate this functionality: https://jsfiddle.net/flexmonster/gxon7rev/
 
Please let us know if the described approach works for you.
 
Best regards,
Mykhailo

Please login or Register to Submit Answer