首页 \ 问答 \ D3.js中的圆圈仅显示没有圆圈的文本(Circle in D3.js only displaying text without circle)

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
更新时间:2022-01-22 14:01

最满意答案

如果我理解你的话,其他一些线程在你的MyApp上调用receiveData来填充数据。 如果这是正确的,那么你就是这么做的:

  1. 你这样睡觉:

    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());
    
  2. receiveData应该发出notify呼叫,以unpause您的wait呼叫。 例如像这样:

    myData.put(field, value);   
    this.notify();
    
  3. 这两个块都需要在this对象上“同步”才能获得它的监视器(这是wait所需的)。 您需要将方法声明为“同步”,或者将各个块放入synchronized(this) {...}块中。


If I understood you right, some other thread calls receiveData on your MyApp to fill the data. If that's right, then here's how you do it:

  1. 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());
    
  2. receiveData should make a notify call, to unpause that wait call of yours. For example like this:

    myData.put(field, value);   
    this.notify();
    
  3. Both blocks will need to be "synchronized" on this object to be able to aquire it's monitor (that's needed for wait). You need to either declare the methods as "synchronized", or put the respective blocks inside synchronized(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的等待通知的示例: 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 ...
  • 您最好使用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 5或更高版本可用,则可以使用CountDownLatch 。 例如,假设主框架最初处于控制状态,让主框架创建CountDownLatch并将倒数计数减1,并将此锁存器传递到登录框架。 然后让主框架等待锁存器变为0: CountDownLatch loginSignal = new CountDownLatch(1); ... // Initialize login frame, giving it loginSignal ... // execute lo ...
  • 如果我理解你的话,其他一些线程在你的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.

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)