C3JS中的群组堆积条形图

时间:2016-10-14 10:45:49

标签: c3.js

如何在一个组中为一个堆积条形图设置一个组?

I have multiple accounts, which have buys and sells. 

I need to display the buys and sells in a stacked bar chart for each account. 

我只能展示购买和出售。棘手的一点是显示每个账户的买入和卖出。任何想法?

1 个答案:

答案 0 :(得分:2)

试试这个:https://jsfiddle.net/tqwxx50a/1

HTML:

<div id="chart1"></div>

使用Javascript:

var months = ['Jan 2016', 'Feb2016'];
var columnData = [
  ['account1buy', 20, 15],
  ['account1sell', 18, 25],
  ['account2buy', 33, 45],
  ['account2sell', 54, 21],
];


var chart = c3.generate({
    bindto: '#chart1',
  data: {
    columns: columnData,
    type: 'bar',

    groups: [['account1buy', 'account1sell'], ['account2buy', 'account2sell']],
  },

  axis: { x: {
    type: 'category',
    categories: months,
  }},
});