传递给 Google Visualization API 时字符串太大导致的错误
我正在尝试通过 WordCloud 创建="http://code.google.com/apis/visualization/documentation/reference.html" rel="nofollow noreferrer">Google 可视化 API。您必须创建一个 google.visualization.DataTable 并将字符串添加到表中的单元格中。我基本上复制了上面链接的示例,并传入了一个由几个单词组成的简单字符串(@note.articletext),WordCloud 工作得很好。
<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>
但我想基于一篇文章创建WordCloud,该文章(显然)是一个非常大的字符串。当我传入包含整篇文章的字符串时,出现以下错误:
unterminated string literal
data.setCell(0, 0, 'There was a da...ne ended with a time-out in his crib.
同样,当我传入小字符串时不会发生此错误,因此这是由字符串的大小引起的。或者可能 google.visualization.DataTable 对单个单元格的大小有限制(尽管我找不到这样的限制)。有谁知道我该如何解决这个问题?感谢您的阅读。
编辑:如果它很重要,我正在使用 Ruby on Rails。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您添加到数据单元的文本很可能跨越多行,导致“未终止的字符串文字”错误。
尝试解析文本并将其全部放在一行中。或者逐行添加单元格。
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.