views:

32

answers:

1

I am trying to create a WordCloud through the Google Visualization API. You have to create a google.visualization.DataTable and add the string to a cell in the table. I basically copied the example linked above, and passed in a simple string of a few words (@note.articletext), and the WordCloud worked fine.

    <script type="text/javascript">
      google.load("visualization", "1");
      google.setOnLoadCallback(draw);
      function draw() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Text1');
        data.addRows(1);
        data.setCell(0, 0, '<%= @note.articletext %>');

        var outputDiv = document.getElementById('wcdiv');
        var wc = new WordCloud(outputDiv);
        wc.draw(data, {width:300, height:300});
      }
    </script>

But I want to create the WordCloud based on a article, which (obviously) is a very large string. When I pass in a string containing a whole article, I get the following error:

unterminated string literal
data.setCell(0, 0, 'There was a da...ne ended with a time-out in his crib.

Again, this error doesn't occur when I pass in a small string, so it's caused by the size of the string. Or potentially the google.visualization.DataTable has a limit on how big a single cell can be (I can't find mention of such a limit though). Does anyone know how can I fix this? Thanks for reading.

Edit: In case it's important, I'm using Ruby on Rails.

+2  A: 

The text you are adding to the datacell most likely spans multiple lines causing the 'unterminated string literal' error.

Try parsing the text and put it all on one line. Or add cells on a line by line basis.

Abarax