Kirill Fuchs
Kirill Fuchs

Reputation: 13686

Why did my previously working google visualization charts stop working after Nov 26th 2013?

1) I am getting Uncaught TypeError: undefined is not a function in code such as:

var moneyFormat = new google.visualization.TableNumberFormat({prefix: '$', fractionDigits: '2'})

2) My Charts stopped showing up as well, here is some example code that can be used in the visualization playground:

function drawVisualization()
  {
    //Area Chart - Monthly Revenue(yoy)
      var revenueData = new google.visualization.DataTable();
      revenueData.addColumn('string', 'Month');
      revenueData.addColumn('number', new Date().getFullYear());
      revenueData.addColumn('number', new Date().getFullYear() - 1);
      revenueData.addRow(['remove', 0, 0]);

      var revnueOptions = {
          animation: {duration: 450, easing: 'inAndOut',},
          hAxis: {title: 'Months',  titleTextStyle: {color: '#546892'}},
          vAxis: {title: 'Revenue',  titleTextStyle: {color: '#546892'}},
          colors: ['#6B9EB8', '#BDBDBD']
      };

          var revenueChart = new google.visualization.AreaChart(document.getElementById('visualization'));
          revenueChart.draw(revenueData, revnueOptions);
          revenueData.removeRow(0);
          revenueData.addRows([["Jan",476720.91,312755.59],["Feb",257814.89,262533.76],["Mar",314711.67,212908.66],["Apr",467195.04,280168.64],["May",378582.63,234551.38],["Jun",423507.6,223820.38],["Jul",354414.55,239495.22],["Aug",276546.96,215121.71],["Sep",301605.96,414958.25],["Oct",536133.65,315029.05],["Nov",533505.83,560722.95],["Dec",0,815092.65]]);
          revenueChart.draw(revenueData, revnueOptions);
  }

Upvotes: 0

Views: 906

Answers (1)

Kirill Fuchs
Kirill Fuchs

Reputation: 13686

Google released some updates on Nov 26th 2013.

For problem 1:

You should be using NumberFormat instead of TableNumberFormat. See: google.visualization.NumberFormat

For problem 2:

the lines:

revenueData.addColumn('number', new Date().getFullYear());
revenueData.addColumn('number', new Date().getFullYear() - 1);

Are passing numbers as the 2nd parameter, this is causing the error. You can add to an empty string +'' or call .toString() to parse them as strings like so:

revenueData.addColumn('number', (new Date().getFullYear())+'');
revenueData.addColumn('number', (new Date().getFullYear() - 1).toString());

It seems before they allowed you to pass numbers in the 2nd parameter and now they enforce strings only.

Upvotes: 3

Related Questions