简体   繁体   English

c3.js中的堆积甜甜圈图

[英]Stacked Donut Chart in c3.js

I would like to customize a donut chart from c3.js so it that has 2 layers. 我想从c3.js定制一个甜甜圈图,使其具有2层。

This is the code for the very basic out of box c3.js based donut chart. 这是基于c3.js的非常基本的现成甜甜圈图的代码。

var chart = c3.generate({
    data: {
        columns: [
            ['bulls', 30],
            ['lakers', 50],
        ],
        type : 'donut'
    },
}); 

This is an image of something similar to what i want to achieve: 这是类似于我想要实现的图像:

在此处输入图片说明

I did find this fiddle but I am not sure on how to implement it in c3.js. 我确实找到了这个小提琴,但是不确定如何在c3.js中实现它。 Here is a link to my fiddle . 这是我的小提琴的链接。

The D3 fiddle is actually creating three charts, each with a different radius. D3小提琴实际上是在创建三个图表,每个图表具有不同的半径。 Each dataset uses "d3.pie" to create the arc that each piece of data will inhabit, and then the graph is being drawn across a path with a radius that is different and increases based on which dataset is being plotted (i=1...4) 每个数据集使用“ d3.pie”创建每条数据将驻留的弧线,然后在半径不同的路径上绘制图形,并根据绘制的数据集来增加该图形(i = 1。 ..4)

Put another way: The D3 fiddle is drawing multiple separate graphs on the same center point so it just looks like they're related. 换句话说,D3提琴在同一个中心点绘制多个单独的图形,因此看起来就像它们是相关的。

I haven't worked directly with C3.js, but you could accomplish something similar to this by creating two charts using the same center point with different radii and widths for each nested chart. 我尚未直接使用C3.js,但是您可以通过使用相同的中心点创建两个图表,并为每个嵌套图表使用不同的半径和宽度来完成与此类似的操作。 (Basically putting one inside the other) The origin coordinate should be the same so as long as the percentages match up they should end up looking like your screenshot image. (基本上将一个放到另一个内)原点坐标应相同,只要百分比匹配,它们的最终外观应类似于您的屏幕快照图像。

Unsure if there is a method to set the center coordinate but you should be able to absolutely position your DIVs on the same spot on the page that can work. 不确定是否有设置中心坐标的方法,但是您应该能够将DIV绝对定位在页面上可以工作的同一位置。

That said, I might recommend moving away from C3.js and instead using the existing D3 fiddle and library and then draw labels / add interactivity as needed as it seems to be a bit more simple and will allow for better customization opportunities for your use case in the future. 就是说,我可能建议您远离C3.js,转而使用现有的D3小提琴和库,然后根据需要绘制标签/添加交互性,因为这似乎更加简单,并且将为您的用例提供更好的自定义机会在将来。 You may also want to consider using a library like NVD3.js which provides access to the core d3 methods alongside their charts so you can crib code from both example donuts and the D3 Fiddle. 您可能还想考虑使用像NVD3.js这样的库,该库提供对核心d3方法及其图表的访问,以便您可以从示例甜甜圈和D3小提琴中获取代码。

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

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