d3饼图从本地json变量

d3饼图从本地json变量

本文介绍了d3饼图从本地json变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用json从局部变量(而不是外部文件)创建一个圆环图。我看到

解决方案

  1. 将JSON变量重命名为 data

  2. 删除 d3.json call(but keep the code within it)。

完成jsfiddle 。您还需要将SVG附加到body而不是#body。


I am trying to create a donut chart using json from a local variable (rather than an external file) I have seen this post but am having a hard time adjusting my code in the same way

In the above example

d3.json("flare.json", function(error, root) {

was replaced with

root = JSON.parse( myjson );

which does not fix my problem

Check out the fiddle below where my data is loaded as variable titled myJson. How can I use this data for the donut?

Fiddle

解决方案
  1. Rename your JSON variable to data.
  2. Delete the d3.json call (but keep the code within it).

Complete jsfiddle here. You also need to append your SVG to "body" and not "#body".

这篇关于d3饼图从本地json变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:42