Search code examples
highchartshighmaps

Highmaps: how can I show an ordered list of U.S. states with population density


I am playing with Highmaps. Here is the example Highmap with U.S. states and their population density:

http://www.highcharts.com/maps/demo/color-axis

It would be nice if I can have a button to click and show an ordered list of states with population density. This would give a much easier and better idea of ordering than on a map.

Is this something out of box? Any pointer is really appreciated.


Solution

  • I think that you should be able to sort your data using js sort method. Here you can find more information about this method: https://developer.mozilla.org/pl/docs/Web/JavaScript/Referencje/Obiekty/Array/sort

    You can make custom compare method for comparing elements of your array. For example if you would like to compare your data by name:

      function compare(a, b) {
        if (a.name < b.name)
          return -1
        if (a.name > b.name)
          return 1
        return 0
      }
    

    Here you can find an example how this method may work with you chart: http://jsfiddle.net/cc84hk3n/2/

    You may sort your data by value as well if you would like to.

    Best,