D3.js中的圆圈仅显示没有圆圈的文本(Circle in D3.js only displaying text without circle)
我正在尝试使用带有文本的d3.js绘制一个圆圈。 这是我的代码:
<script src="//d3js.org/d3.v3.min.js"></script> <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> <div class="circles"></div> <script> $(document).ready(function () { circles(); $(".circles").show(); function circles() { var svg = d3.select(".circles"); var groups = svg.selectAll("div") .data("DEMO") .enter() .append("div"); groups.attr("transform","translate(" +100+ "," +100+ ")"); var circles = groups.append("circle") .attr("cx", "100") .attr("cy","100") .attr("r", "100") .attr("fill", "red") .attr("stroke-width","2.4192") .attr("stroke","#00ffff"); var label = groups.append("text") .text(function(d){ return d; }) .attr({ "alignment-baseline": "middle", "text-anchor": "middle", "font-family":"Arial", "font-size":"30", "fill":"white" }); } }); </script>
但它只显示文本,并且没有显示圆圈。 我无法修复它。 任何人都可以指出我的错误,并帮助我解决它。
I am trying to draw a circle using d3.js with text inside it. Here is my code:
<script src="//d3js.org/d3.v3.min.js"></script> <script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> <div class="circles"></div> <script> $(document).ready(function () { circles(); $(".circles").show(); function circles() { var svg = d3.select(".circles"); var groups = svg.selectAll("div") .data("DEMO") .enter() .append("div"); groups.attr("transform","translate(" +100+ "," +100+ ")"); var circles = groups.append("circle") .attr("cx", "100") .attr("cy","100") .attr("r", "100") .attr("fill", "red") .attr("stroke-width","2.4192") .attr("stroke","#00ffff"); var label = groups.append("text") .text(function(d){ return d; }) .attr({ "alignment-baseline": "middle", "text-anchor": "middle", "font-family":"Arial", "font-size":"30", "fill":"white" }); } }); </script>
But it displays only the text and the circle is not being displayed. I am unable to fix it. Can anyone please point out my mistake and help me fix it.
原文:https://stackoverflow.com/questions/35388385
最满意答案
如果我理解你的话,其他一些线程在你的
MyApp
上调用receiveData
来填充数据。 如果这是正确的,那么你就是这么做的:
你这样睡觉:
do { this.wait(someSmallTime); //We are aquiring a monitor on "this" object, so it would require a notification. You should put some time (like 100msec maybe) to prevent very rare but still possible deadlock, when notification came before this.wait was called. } while (!allFieldsAreFilled());
receiveData应该发出
notify
呼叫,以unpause
您的wait
呼叫。 例如像这样:myData.put(field, value); this.notify();
这两个块都需要在
this
对象上“同步”才能获得它的监视器(这是wait
所需的)。 您需要将方法声明为“同步”,或者将各个块放入synchronized(this) {...}
块中。If I understood you right, some other thread calls
receiveData
on yourMyApp
to fill the data. If that's right, then here's how you do it:
You sleep like this:
do { this.wait(someSmallTime); //We are aquiring a monitor on "this" object, so it would require a notification. You should put some time (like 100msec maybe) to prevent very rare but still possible deadlock, when notification came before this.wait was called. } while (!allFieldsAreFilled());
receiveData should make a
notify
call, tounpause
thatwait
call of yours. For example like this:myData.put(field, value); this.notify();
Both blocks will need to be "synchronized" on
this
object to be able to aquire it's monitor (that's needed forwait
). You need to either declare the methods as "synchronized", or put the respective blocks insidesynchronized(this) {...}
block.
相关问答
更多-
在“版本2”中,您正在中断调用stopParser()的线程,而不是正在执行run()的线程。 而不是调用Thread.currentThread().interrupt() ,使用myThread.interrupt() 。 我不知道为什么你会在“版本1”中遇到InterruptedException; 你必须在其他地方调用Thread.currentThread().interrupt() 。 只有当您检测到当前线程已被另一个线程中断但您无法立即终止线程时,才应执行此操作。 In "version 2" ...
-
通过Dataproc REST API,在作业上调用GET将返回有关作业状态的信息。 通常,您只需要一个轮询循环: public static final ImmutableSet
TERMINAL_JOB_STATES = ImmutableSet.of("CANCELLED", "DONE", "ERROR"); // Initialize this as normal with credentials, setAppName, HttpTransport, etc. priv ... -
如何实现等待,用java中的threadexecutor通知(how to implement wait,notify with threadexecutor in java)[2023-11-02]
以下是在Java中使用ThreadExecutor的等待通知的示例: public class ExecutorServiceTest { /** * @param args the command line arguments */ public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); Th ... -
您可以查看有关内部锁和同步的Java文档 每个对象都有一个与之关联的内在锁。 按照惯例,需要对对象字段进行独占和一致访问的线程必须在访问对象之前获取对象的内部锁,然后在完成它们时释放内部锁。 一个线程被称为在获得锁定和释放锁定之间拥有内在锁定。 只要一个线程拥有一个内部锁,没有其他线程可以获得相同的锁。 另一个线程在尝试获取锁时将阻塞。 还有这个: You can have a look at the Java documentation about Intrinsic Locks and Synchron ...
-
在Java中使用wait()(Use wait() in Java)[2022-11-08]
您最好使用Synchronizers而不是wait和notify 。 由于简单和安全,它们更优选。 鉴于正确使用wait和notify的困难,您应该使用更高级别的并发实用程序。 Effective Java(第2版),第69项 I solved with this class: import java.awt.Dimension; import java.util.ArrayList; import java.util.List; import javax.swing.JComponent; import ... -
这是2秒延迟Runnable的示例 final Handler handler = new Handler(); final Runnable runnable = new Runnable() { @Override public void run() { // Do stuff handler.postDelayed(this, 2000); } }; handler.postDelayed(runnable, 2000); Here is ...
-
在sendMulticast事件中等待X秒开始等待 只需使用带有超时参数的wait()版本。 请注意,您应该在每次成功调用wait()之后手动更新超时值(即返回事件)。 将所有收到的事件添加到列表后,在receiveEventsCallback()处通知。 您的问题坚持认为您不知道网络中有多少听众。 你怎么知道,所有人都收到了事件(和回复)? 发送者的唯一方法是等待X秒并处理所有可用的回复,直到那一刻。 Start a wait at the sendMulticast event for X second ...
-
Java等待JFrame完成(Java wait for JFrame to finish)[2022-08-23]
如果您有Java 5或更高版本可用,则可以使用CountDownLatch 。 例如,假设主框架最初处于控制状态,让主框架创建CountDownLatch并将倒数计数减1,并将此锁存器传递到登录框架。 然后让主框架等待锁存器变为0: CountDownLatch loginSignal = new CountDownLatch(1); ... // Initialize login frame, giving it loginSignal ... // execute lo ... -
在Java中等待的最佳方式(Best way to wait in Java)[2023-07-09]
如果我理解你的话,其他一些线程在你的MyApp上调用receiveData来填充数据。 如果这是正确的,那么你就是这么做的: 你这样睡觉: do { this.wait(someSmallTime); //We are aquiring a monitor on "this" object, so it would require a notification. You should put some time (like 100msec maybe) to prevent very rare bu ... -
文档说: trait Future[+T] extends Awaitable[T] 未来是可以等待的。 the docs say: trait Future[+T] extends Awaitable[T] The future is an awaitable.