Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google charts histogram not using histogram.bucketSize option

I'm trying to make a basic histogram with Google Charts, but for some reason it's not using the bin width that I set. Below is a code sample:

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load("current", {packages:["corechart"]});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['MyData', 'Value']
                    , ['whatevs', .57]
                    , ['whatevs', .57]
                    , ['whatevs', .57]
                    , ['whatevs', .8]
                    ]);

        var options = {
          title: 'My Histogram'
          , legend: { position: 'none' }
                    , histogram: {
                        bucketSize: .1
                    }
        };

        var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

and here's an image of what happens:

enter image description here

but what I would like to happen would be for the bins to be uniformly sized at a width of 0.1.

like image 837
George Avatar asked Dec 15 '25 18:12

George


2 Answers

This appears to be a bug introduced in Charts API version 44. You can roll back to version 43 by specifying the version number when you load the library:

google.charts.load("43", {packages:["corechart"]});
like image 63
Kevin Schellenberg Avatar answered Dec 17 '25 06:12

Kevin Schellenberg


It seems like this is the result of a bug that can be fixed by adding hAxis: { type: 'category' } to the options.

like image 31
George Avatar answered Dec 17 '25 07:12

George



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!