C3中具有JSON数据的多个Y轴

时间:2016-10-14 11:06:44

标签: javascript d3.js charts c3.js

当尝试将json数据映射到c3 js中的多个y轴时,第二个轴不会缩放到数据,而是显示0-1。有任何改变它的想法吗?

1 个答案:

答案 0 :(得分:1)

var chart = c3.generate({
  bindto: '#chart',
  data: {
    json: [{
        "name": "google search",
        "Lead": 250,
        "Conversion": 59,
        "Rate": 50
      },
      {
        "name": "facebook advertisement",
        "Lead": 104,
        "Conversion": 20,
        "Rate": 60
      },
      {
        "name": "ST Ads",
        "Lead": 200,
        "Conversion": 123,
        "Rate": 70
      }
    ],
    keys: {
      x: 'name',
      value: ['Lead', 'Conversion', 'Rate'],
    },
    axes: {
      'Rate': 'y2'
    },
    type: 'bar',
    types: {
      'Rate': 'line'
    }
  },
  axis: {
    x: {
      type: 'category'
    },
    y2: {
      show: true
    }
  }
});