简体   繁体   English

运行D3.js示例

[英]Running D3.js Example

I've been trying to learn D3, but I've been having trouble running the circle example. 我一直在尝试学习D3,但是在运行圈子示例时遇到了麻烦。

http://mbostock.github.com/d3/tutorial/circle.html

I am just trying to run the step where the circles change colors and size. 我只是尝试执行以下步骤,即圆圈更改颜色和大小。

All I did was copy and paste, the example but I don't know how else to approach this 我所做的只是复制和粘贴示例,但我不知道该如何处理

http://jsfiddle.net/NntGN/

I've been trying to work through the tutorial to resolve this issue : 我一直在尝试完成本教程来解决此问题:

http://jsfiddle.net/H2SKt/1/

If you look at the pie chart, the names are blocked out. 如果您查看饼图,则名称将被屏蔽。 What changes would I need to make such that all the labels are pointing toward the center of the pie chart and not blocking each other? 我需要进行哪些更改,以使所有标签都指向饼图的中心而不互相阻塞? I've been playing with the text anchor and feel that its my best bet, but I'm not making any progress. 我一直在使用文本锚,并认为这是我最好的选择,但是我没有取得任何进展。

Thanks for any help :) 谢谢你的帮助 :)

Well first of all you don't have to copy the following html code to your site: 首先,您不必将以下html代码复制到您的网站:

<svg width="360" height="180">
  <circle class="little" cx="180" cy="45" r="12"></circle>
  <circle class="little" cx="60" cy="90" r="12"></circle>
  ...
</svg>

That does d3.js for you. 那为您做了d3.js。 You just have to write the javascript code to select an svg element (or append one to your body for example) and to create the elements. 您只需要编写JavaScript代码即可选择一个svg元素(例如,将一个svg元素附加到您的身体上)并创建这些元素。 Your code doesn't work because svg is not defined. 您的代码无效,因为未定义svg

Have a look at the section Creating Elements in the circle tutorial . 请参阅圈子教程中的“ 创建元素 ”部分。

And last but not least here is the working jsfiddle . 最后但并非最不重要的一点是可工作的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM