Home Forums Chart Support stacked rangebar order by date

stacked rangebar order by date

Viewing 4 posts - 1 through 4 (of 4 total)
  • #42172

    Can someone do an example of how to sort by date on a stacked rangebar chart?

    I have a java-millisecond date field named orderDate that I would like to use to order a stacked rangebar chart.

    I am trying to use the following example but the order seems to be using the lineCounter order that makes the stacked rangebar work.

                    chart.options.data.forEach(function (element) {
                        element.dataPoints.sort(compareDataPoint);
                    });
    
    				//descending order
    				//chart.options.data[0].dataPoints.sort(compareDataPointYDescend);
    
    				chart.render();
    
                    function compareDataPoint(dataPoint1, dataPoint2) {
                        // instead of label you can also use dataPoint.x  or dataPoint.y depends on you requirment
                        if (dataPoint1.sortDate < dataPoint2.sortDate) { return -1 }
                        if (dataPoint1.sortDate > dataPoint2.sortDate) { return 1 }
                        return 0
                    }
    #42174

    @dpanscik,

    Sorting datapoints by x values using the below code snippet seems to be working fine for data-time values as well. Please check this JSFiddle for a working example.

    function compareDataPointX(dataPoint1, dataPoint2) {
      return dataPoint1.x - dataPoint2.x;
    }

    If you are still facing issues, kindly create a sample project reproducing the issue and share it with us over Google Drive or OneDrive so that we can look into the code, run it locally to understand the scenario better, and help you out.


    Thangaraj Raman
    Team CanvaSJS

    #42177

    stacked stacked rangebar and sorting seems to be an issue.

    I couldnt get sorting working with stacked rangebar.

    I decided instead to do the sorting within the MVC controller before pushing the data to the chart.

    Problem solved.

    #42184

    @dpanscik,

    Glad that you were able to figure it out.


    Thangaraj Raman
    Team CanvasJS

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

You must be logged in to reply to this topic.