简体   繁体   English

json数组中的c3js堆积条形图

[英]c3js Stacked Bar chart from json array

Guys this is the problem: I have a timeseries stacked bar chart written with c3js, and it works really nice. 伙计们,这就是问题所在:我有一个用c3js编写的时间序列堆积条形图,它的确非常好。 but I still need to create a stacked bar chart with the same data BUT as a category chart... 但我仍然需要创建一个堆叠的条形图, 其数据与类别图相同。

my Json looks like this: 我的Json看起来像这样:

{"product":"acucar5kg","bundle":0,"units":5342,"production":26710,"label":"acuuki 5kg","line":"Empacotamento 1","date":"2017-10-02"}

and my original chart is like this: 我的原始图表是这样的:

  • x-axis: date x轴:日期
  • y-axis: production y轴:生产
  • groups: label 组:标签

my objective is to have 我的目标是

  • x-axis: line x轴:线
  • y-axis: production y轴:生产
  • groups: label 组:标签

to make it simple my original code is over here: code on jsfiddle and cheating real quick for anyone to understand what i really want... here is the mockup 为了简单起见 ,我的原始代码在这里: jsfiddle上的代码,让任何人都可以很快地骗出我真正想要的东西...这是样机 新图表

Save me plz !! 请救我! =* = *

ps feel free to smite and bash my code... i`m not a good JS dev... yet! ps随时可以sm打我的代码...我不是一个好的JS开发人员...! Thanks! 谢谢!

Well, took me some time but here is a fiddle what do you need. 好吧,花了我一些时间,但是是一个小玩意儿。 To works I did: 我所做的工作:

Change the line in return d.line; 更改行以return d.line; for the nestedData object and the obj.line = entry.key; 用于nestedData对象和obj.line = entry.key; for the formatedData object. 用于formatedData对象。 Also make changes to the properties x: 'line', and the type type: 'category' in the generate method. 还可以在generate方法中更改属性x: 'line',和类型type: 'category'

Check and tell me if that works for you. 检查并告诉我是否适合您。

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

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