gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:19:05 26 4
gpt4 key购买 nike

我只想显示“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);

最佳答案

使用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

关于javascript - 更新c3.js中条形图的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46650535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com