一般的解決方案是存儲與點圖本身分開的工具提示。通過組ID和數據索引
和訪問他們:
var tooltips = {
mention1: ['ROA=5.1%','ROA=8.1%','ROA=4.1%','ROA=10.1%'],
mention2: ['ROA=5.1%','ROA=8.1%','ROA=4.1%','ROA=10.1%'],
mention3: ['2000 ROA=2.2%','2001 ROA=8.2%','2002 ROA=5.2%','2005 ROA=12.2%'],
mention4: ['2000 ROA=2.2%','2001 ROA=8.2%','2002 ROA=5.2%','2005 ROA=12.2%']
}
var chart = c3.generate({
data: {
xs: {
mention1: 'engagement1',
mention2: 'engagement2',
mention3: 'engagement3',
mention4: 'engagement4'
},
columns: [
['engagement1', 140, 150, 157, 220],
['mention1', 2237, 4456, 3300, 1453],
['engagement2', 40, 50, 57, 120],
['mention2', 2237, 4456, 3300, 1453],
['engagement3', 150, 155, 165, 230],
['mention3', 2037, 4756, 3100, 1053],
['engagement4', 50, 55, 65, 130],
['mention4', 2037, 4756, 3100, 1053]
],
type: 'scatter'
},
point: {
r: function(d) {
return d.value * 0.005;
},
},
tooltip: {
contents: function (d) {
var id = d[0].id; // 'mention1', 'mention2' ...
var index = d[0].index; // 1,2,3,4 ...
// replace plain data with custom markup or copy c3's default
return tooltips[id][index]; // 'ROA=...'
}
}
});
見fiddle
請你設置的jsfiddle或codepen? –
這裏是jsfiddle網址[jsfiddle](https://jsfiddle.net/laguna92651/t1aLbc0d/) – user8038235