gpt4 book ai didi

c3.js - 从 C3.js 条形图中排除零值

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

让我们以下面的图表 http://c3js.org/samples/chart_bar.html 为例
但是用下面的数据替换列数据:

var chart = c3.generate({
data: {
columns: [
['data1', 30, 0, 100, 0, 150, 250],
['data2', 130, 0, 140, 200, 0, 50]
],
type: 'bar'
},
bar: {
width: {
ratio: 0.5 // this makes bar width 50% of length between ticks
}
// or
//width: 100 // this makes bar width 100px
}
});

setTimeout(function () {
chart.load({
columns: [
['data3', 130, -150, 200, 300, -200, 100]
]
});
}, 1000);

正如我们所看到的,我们有很多空白或零值条,我们如何删除它并删除空白。 (不是隐藏,我知道如何用 CSS 隐藏它)

Image example, what should be removed

最佳答案

正如在 https://github.com/c3js/c3/issues/81 中搜索的那样
您需要将 0 替换为 'null' 并添加以下内容:

    line: {
connectNull: true,
},

var chart = c3.generate({
data: {
columns: [
['data1', 30, null, 100, null, 150, 250],
['data2', 130, null, 140, 200, null, 50]
],
line: {
connectNull: true,
},
type: 'bar'
},
bar: {
width: {
ratio: 0.5 // this makes bar width 50% of length between ticks
}
// or
//width: 100 // this makes bar width 100px
}
});

setTimeout(function () {
chart.load({
columns: [
['data3', 130, -150, 200, 300, -200, 100]
]
});
}, 1000);

关于c3.js - 从 C3.js 条形图中排除零值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34920720/

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