Home forums Using CanvasJS Order by Value

This topic contains 2 replies, has 3 voices, and was last updated by  Saurabh singh 3 months, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9286

    tufweb
    Member

    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

    Thanks

    #9292

    tufweb,

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

    #15798

    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) {
        element.dataPoints.sort(compareDataPoint);
    	});
    	chart.render();
    }
    
    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
    }
    
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.