更新c3.js中条形图的数据

时间:2017-10-09 15:58:50

标签: javascript d3.js c3.js

我想只显示'data1'数据。因为我正在做超时。但它仍然显示'data2'的值。我该如何解决?

https://jsfiddle.net/1q5zyftL/

  var data1=[['data1', 35, 205, 150, 100, 100, 200], ['data2', 130, 120, 130, 190, 100, 40]];

  var chart = c3.generate({
      data: {
          columns: [
              ['data1', 30, 200, 100, 400, 150, 250],
              ['data2', 130, 100, 140, 200, 150, 50]
          ],
          type: 'bar',
          labels:true
      },
      type: 'bar',

      bar: {
          width: {
              ratio: 0.5 // this makes bar width 50% of length between ticks
          }
      },
      axis: {
       rotated: true
      }
  });


  setTimeout(function () {
      chart.load({
          columns: [
             data1[0]
          ]
      });
  }, 1000);

1 个答案:

答案 0 :(得分:1)

使用unload()方法删除数据ID。

var data1=[['data1', 35, 205, 150, 100, 100, 200], ['data2', 130, 120, 130, 190, 100, 40]];

var chart = c3.generate({
    data: {
        columns: [
            ['data1', 30, 200, 100, 400, 150, 250],
            ['data2', 130, 100, 140, 200, 150, 50]
        ],
        type: 'bar',
        labels:true
    },
    type: 'bar',

    bar: {
        width: {
            ratio: 0.5 // this makes bar width 50% of length between ticks
        }
    },
    axis: {
     rotated: true
    }
});


setTimeout(function () {
    chart.unload({
        ids: ['data2']
    });
}, 1000);

Updated fiddle