Search code examples
javascriptgoogle-visualization

Get Number of unique rows in google charts timeline


I am using the google charts api to visualize some data on my app. Currently I have a timeline set up where I set the height of the timeline depending on how many rows are in the data. The following is the code:

var paddingHeight = 40;
var rowHeight = dataTable.getNumberOfRows() * 15;
 var options = {
                height:chartHeight,
}

The problem is that my timeline has many duplicate rows in the table and therefore the height of the timeline gets messed up. For example, dataTable.getNumberOfRows() will calculate 100 rows in the table however there are only 10 unique rows. This causes the height of the chart to be way off. How can I simply calculate the number of unique rows in the timeline. Any help is greatly appreciated.


Solution

  • I couldn't achieve this using the a google charts method. So I had to do it before I created the datatable variable. The data imported to google charts was in the form of a 2-d array. Here's the code to get the number of unique rows:

    var dups=[];
    for(var i=0;i<data.length;i++){
        if(!dups.includes(data[i][1])){
             dups.push(data[i][1])
    }
                }