Home Forums Chart Support Order by Value

Order by Value

Viewing 5 posts - 1 through 5 (of 5 total)
  • #9286

    hi i am getting value from php mysql. is there any option that i can sort the values like 1st value can heigher value. and so on

    echo ” { x: new Date(“.$DDateArr[‘0’].”,”.$DDateArr[‘1’].”,01), y: “.$qq.”},”. PHP_EOL;

    abc = 150
    xyz = 160

    can i order this in this graph ???????
    xyz = 160
    abcd = 150




    Sort feature is not available out of the box. But with just a few lines of code you can do the same.


    yes it was very help full for string comparison you can you below code.

    function displayGraph(graphData){
    var chart = new CanvasJS.Chart("chartContainer1",graphData);
    	chart.options.data.forEach(function(element) {
    function compareDataPoint(dataPoint1, dataPoint2) {
    // instead of label you can also use dataPoint.x  or dataPoint.y depends on you requirment
    	if (dataPoint1.label < dataPoint2.label){return -1}
    	if ( dataPoint1.label > dataPoint2.label){return 1}
    	return 0


    the solution from Saurabh singh works great with a single bar chart.
    But how can we sort a multi series bar chart by the first value?

    Thanks in advance
    best regards, rodolfo



    The solution seems to be working fine with multi-series bar chart as shown in this JSFiddle.

    If you are still facing the issue, can you kindly create JSFiddle reproducing the issue you are facing and share it with us along with further briefing so that we can understand your scenario better and help you out?

    Manoj Mohan
    Team CanvasJS

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.