user3172663
user3172663

Reputation: 312

Sorting Bar chart in C3js

I was looking forward to sort the bars on simple bar-chart, if it is possible something like below i mentioned.

var chart = c3.generate({ data: { columns: [['data1', 30, 200, 100, 400, 150, 250],], type: 'bar', order: 'desc' }, })

Upvotes: 0

Views: 1130

Answers (1)

altocumulus
altocumulus

Reputation: 21578

As per the documentation the data.order property is restricted to pie or donut charts. You have to sort the data before creating the chart to get ordered bars.

var data1 = [130, 100, 140, 200, 150, 50].sort(function(a,b) { return a-b; })
var chart = c3.generate({
  data: {
    columns: [
        ["data1"].concat(data1)  // old-school
//      ["data1", ...data1]      // ES6 flavor

    ]
  }
})

Upvotes: 1

Related Questions