- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 vega.js 的帮助下使用一系列字符串创建一个词云,同时逐个添加文本,我想更新我的词云。我的代码如下所示。 wordCloud 仅针对第一个文本字符串进行绘制。对于下一个字符串,它会在浏览器控制台上给出此错误。“view.data 未定义”有人可以帮我找到我的代码的解决方案吗?
$(document).ready(function(){
drawCloud("wordCloud");
});
function drawCloud(Htag){
var htag="#"+Htag; var i=0;
var TextData =["#Trump Where was Trump when Cruz was fighting Rubio and Schumer on amnesty for illegals? Cruz is the true conservative.","#RealDonaldTrump is the greatest business mind: https://t.co/nJZdbmkpJG https://t.co/pivvj0nvje","Trending Now: #Trump | #Oregon | #Debate | #Up | #China | #Sanders | #After | #Bundy | #Leader | #Obama via https://t.co/942kPJKfeu#RealDonaldTrump will save us: https://t.co/cSpSIMH5W9 https://t.co/AYUHae69bb","#RealDonaldTrump is the greatest business mind: https://t.co/nJZdbmkpJG https://t.co/W8LvHyQl9l","You change default value in MySQL configuration file (option connect_timeout in mysqld section) -","Also there are two other timeouts too which are configurable by above methods; wait_timeout & interactive_timeout. For detailed information check link; rackspace.com/knowledge_center/article/"];
var textData="";
var stopWords ="(i|me|my|myself|we|us|our|just|ours|ourselves|you|your|yours|yourself|yourselves|he|him|his|himself|she|her|hers|herself|it|its|itself|they|them|their|theirs|themselves|what|which|who|whom|whose|this|that|these|those|am|is|are|was|were|be|been|being|have|has|had|having|do|does|did|doing|will|would|should|can|could|ought|i'm|you're|he's|she's|it's|we're|they're|i've|you've|we've|they've|i'd|you'd|he'd|she'd|we'd|they'd|i'll|you'll|he'll|she'll|we'll|they'll|isn't|aren't|wasn't|weren't|hasn't|haven't|hadn't|doesn't|don't|didn't|won't|wouldn't|shan't|shouldn't|can't|cannot|couldn't|mustn't|let's|that's|who's|what's|here's|there's|when's|where's|why's|how's|a|an|the|and|but|if|or|because|as|until|while|of|at|by|for|with|about|against|between|into|through|during|before|after|above|below|to|from|up|upon|down|in|out|on|off|over|under|again|further|then|once|here|there|when|where|why|how|all|any|both|each|few|more|most|other|some|such|no|nor|not|only|own|same|so|than|too|very|say|says|said|shall|trump|donaldtrump|hillary|clinton|hillaryclinton|ted|cruz|tedcruz|rick|santorum|ricksantorum|marco|rubio|marcorubio|mike|huckabee|mikehuckabee|martin|omalley|martinomalley|carly|fiorina|carlyfiorina|rand|paul|randpaul|john|kasich|johnkasich|ben|carson|bencarson|lindsley|graham|lindsleygraham|scott|walker|scottwalker|jim|gilmore|jimgilmore|jeb|bush|jebbush|http|https|chris|christie|chrischristie|pataki|george|georgepataki|election|election2016)";
var colorRange=["#fc61e2","#7d3070","#511f49"];
var width = $(htag).width();
var height = $(htag).height();
var text={};
var view={}; var viewUpdateFunction;
for(;i<TextData.length;i++){
var shortText= TextData[i];
var urlRegex = /(https?:\/\/[^\s]+)/g;
var characterRegex=/[^a-z]+|\s+/gmi;
shortText =shortText.replace(urlRegex," ").replace(characterRegex," ");
if(i==0){
text={
"width":width,
"height": height,
"padding": {"top":0, "bottom":0, "left":0, "right":0},
"data": [
{
"name": "table",
"values": [ shortText
],
"transform": [
{
"type": "countpattern",
"field": "data",
"case": "upper",
"pattern": "[\\w']{3,}",
"stopwords": stopWords
},
{
"type": "formula", "field": "angle",
"expr": "[-45, 0, 45][~~(random() * 3)]"
},
{
"type": "formula", "field": "weight",
"expr": "if(datum.text=='VEGA', 600, 300)"
},
{
"type": "wordcloud",
"size": [800, 400],
"text": {"field": "text"},
"rotate": {"field": "angle"},
"font": {"value": "Arial"},
"fontSize": {"field": "count"},
"fontWeight": {"field": "weight"},
"fontScale": [10, 40]
}
]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"range":["#fc61e2","#7d3070","#511f49"]
}
],
"marks": [
{
"type": "text",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": "layout_x"},
"y": {"field": "layout_y"},
"angle": {"field": "layout_rotate"},
"font": {"field": "layout_font"},
"fontSize": {"field": "layout_fontSize"},
"fontStyle": {"field": "layout_fontStyle"},
"fontWeight": {"field": "layout_fontWeight"},
"text": {"field": "text"},
"align": {"value": "center"},
"baseline": {"value": "alphabetic"},
"fill": {"scale": "color", "field": "text"}
},
"update": {
"fillOpacity": {"value": 1}
},
"hover": {
"fillOpacity": {"value": 0.5}
}
}
}
]
};
viewUpdateFunction = (function(chart) {
view = chart({el:htag}).update();
}).bind(view);
vg.parse.spec(text, viewUpdateFunction);
}else{
view.data.values.insert([{shortText}]);
view.update();
}
}
}
<html lang="en">
<head>
</head>
<body >
<!-- Page Content -->
<div class="container">
<!-- Page Header -->
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1 class="page-header text-center">Vega</h1>
<h2 class="page-sub-header text-center">Word Cloud</h2>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8">
<h3>Wword Cloud Example</h3>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="cloudWord-graph" style="width:800px; length:800px; " id="wordCloud"></div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.10/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</body>
</html>
最佳答案
我找到了答案。我已经把解决方案放到了github上。 https://github.com/GDRDABARERA/UpdatingVegaWordCloud
关于javascript - 使用 vega 创建更新的词云,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35157212/
我有以下案例要解决。 在短语中突出显示关键字的 Javascript 方法。 vm.highlightKeywords = (phrase, keywords) => { keywords =
我要匹配文本中的所有美元符号单词。例如,"Hello $VARONE this is $VARTWO"可以匹配$VARONE和$VARTWO。 正则表达式应该是/\$(\w+)/g,但是当我在Dart
在 redux 中,对于将状态作为参数、更改状态并返回新状态的特定操作,您会在 switch 语句中调用什么函数? function reducer(state = DEFAULT_STATE, ac
在 MySQL 5.1 中,我将一个字段命名为“Starting”。但是,每次我使用 SQL 查询时,它都会说无效的 SQL 语法。经过一些谷歌搜索,我发现 STARTING 是一个保留的 SQL 词
我必须使用函数 isIn(secretWord,lettersGuessed) 从列表中找到密码。在下面发布我的代码。 def isWordGuessed(secretWord, lettersGue
一段时间以来,我一直无法找到两个字符串中最长的常用词。首先我想到了用“isspace”函数来做这件事,但不知道如何找到一个常用词。然后我想到了“strcmp”,但到目前为止我只能比较两个字符串。我在想
我目前正在尝试制作一种“单词混合器”:对于两个给定的单词和指定的所需长度,程序应返回这两个单词的“混合”。然而,它可以是任何类型的混合:它可以是第一个单词的前半部分与第二个单词的后半部分相结合,它可以
如果 After 之后(逗号之前)没有 -ing 词,我想匹配它。所以 After 和逗号之间不应该有 -ing 词。 所需的匹配项(粗体): After sitting down, he began
我一直在试验 Stanford NLP 工具包及其词形还原功能。我很惊讶它如何使一些词词形还原。例如: depressing -> depressing depressed -> depressed
js 并尝试根据 [这里] 中的示例代码来做词云:https://github.com/jasondavies/d3-cloud .我想做的是单词的字体大小是基于数组中单词的频率。例如我有 [a,a,
我正在处理一个文本分类问题(在法语语料库上),并且正在试验不同的词嵌入。我对 ConceptNet 提供的内容非常感兴趣,所以我决定试一试。 我无法为我的特定任务找到专门的教程,所以我听取了他们的建议
当我在文本中搜索时,我输入 C-s,然后输入单词,然后一次又一次地输入 C-s,光标前进到找到的单词的下一个位置。问题是,一旦我转到下一个单词,我无法在按钮处编辑迷你缓冲区中的搜索单词,如果我按 Ba
我正在尝试按照以下结构运行这个 maven Hello Word: ├── pom.xml └── src └── Main.java 使用pom.xml设置: 4.0.0
所以,从我可以开始的.. 我正在使用 OCR。该脚本非常适合我的需要。它检测单词的准确性对我来说还可以。 这是结果:附加图像 100% 准确。 from PIL import Image import
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
这是细节,但我想知道为什么会这样。 示例代码: Class klasa = Enum.class; for(Type t : klasa.getGenericInterfaces()) Syst
我在用: var header = ""+ "Export HTML to Word Document with JavaScript"; var footer = ""; /
我有一个程序可以像这样将数据打印到控制台(以空格分隔): variable1 value1 variable2 value2 variable3 value3 varialbe4 value4 编辑:
我有一个程序可以像这样将数据打印到控制台(以空格分隔): variable1 value1 variable2 value2 variable3 value3 varialbe4 value4 编辑:
最近我在查看与goliath相关的一些代码时,偶然在Ruby代码中看到了这个词use。 , 中间件等。看起来它不同于include/extend, and require. 有人可以解释为什么存在这个
我是一名优秀的程序员,十分优秀!