Aggregating a column in a Scatter plot using strings as bins

8 views
Skip to first unread message

Roan Moore

unread,
Feb 25, 2018, 9:39:38 PM2/25/18
to Google Visualization API
Hello all,

I'm brand new to google charts so forgive me if I'm approaching this all wrong.

I've got some data that I'm trying to plot, which is in Day and Time format (for example: 'Thursday', '12:42:00'). I've converted the time format to a timeofday array, but I'm leaving the day in string format.

What I'm trying to do is collect and display all points on a scatter plot for the time of day associated with the day. Something like this:


However, I can only get this result if I use a number for Day. If I try to plot with strings, I get this:


As you can see, the x labels are not aggregated. Here is my code - any help is appreciated. Thanks!


google.charts.load('current', {'packages':['scatter']});
google
.charts.setOnLoadCallback(drawChart);


function drawChart () {
   
var data = new google.visualization.DataTable();
    data
.addColumn('number', 'Day');
    data
.addColumn('timeofday', 'Time of Day');

   
// S=1, M=2, T=3, W=4, T=5, F=6, S=7
   
// This works, but no labels...
   
/*
    data.addRows([
          [3, [0, 45, 0]],
          [3, [11, 45, 0]],
          [6, [21, 45, 0]],
          [3, [12, 40, 0]],
          [6, [11, 25, 0]],
          [6, [10, 25, 0]],
          [2, [11, 15, 0]]
        ]);
    */


   
// This doesn't work
    data
.addRows([
         
['Tuesday', [0, 45, 0]],
         
['Tuesday', [11, 45, 0]],
         
['Friday', [21, 45, 0]],
         
['Tuesday', [12, 40, 0]],
         
['Friday', [11, 25, 0]],
         
['Friday', [10, 25, 0]],
         
['Monday', [11, 15, 0]]
       
]);

   
var options = {
       width
: 800,
       height
: 500,
       selectionMode
: 'multiple',
       aggregationTarget
: 'category',
       chart
: {title: 'Timeline'},
       axes
: {x: {0: {side: 'bottom'}}}
    };

   
var chart = new google.charts.Scatter(document.getElementById('scatter_top_x'));
    chart
.draw(data, options)
}








Reply all
Reply to author
Forward
0 new messages