d3饼图从本地json变量 [英] d3 piechart from local json variable

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

问题描述

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

在上面的例子中

/ p>

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

  root = JSON替换

parse(myjson);

这不能解决我的问题



检查下面的数据是否以标题为myJson的变量的形式加载的数据。如何使用这个数据用于甜甜圈?



小提琴

解决方案


  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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆