我正在探索c3.js,我创建了一个甜甜圈图表,这很容易做,接下来我想做的事情是在mouser-over上我想展开/缩放/突出重点细分,这个功能我们可以在d3pai.看到,但我试图达到纯粹使用c3.js的效果。 可以有人请告诉我如何继续以及如何创建这种段效应的弹出。C3.js甜甜圈图,成长段
var init = function() {
var chart = c3.generate({
data: {
x: 'x',
columns: [
['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'],
['Coin1', 30, 200, 100, 400, 150, 250],
['Coin2', 130, 100, 140, 200, 150, 50],
['Coni3', 50, 100, 130, 240, 200, 150],
['Coin4', 130, 100, 140, 200, 150, 50],
['Coin5', 130, 150, 200, 300, 200, 100]
],
type: 'donut',
onclick: function(e) {
//console.log(e);
// console.log(d3.select(this).attr("stroke-width","red"));
},
onmouseover: function(d, i) {
},
onmouseout: function(d, i) {
}
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d',
centered: true,
position: 'inner-right'
}
}
},
bindto: '#dash',
bar: {
width: {
ratio: 0.5 // this makes bar width 50% of length between ticks
}
},
pie: {
expand: true,
},
tooltip: {
grouped: false,
contents: function(data, defaultTitleFormat, defaultValueFormat, color) {
// console.log("Containt");
// console.log(data, defaultTitleFormat, defaultValueFormat, color);
return "<p style='border:1px solid red;'>" + data[0].value + "</p>";
}
}
});
};
inti();
p {
line-height: 1;
font-weight: bold;
padding: 5px 12px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 4px;
line-height: 15px;
font-size: 12px;
min-width: 91px;
}
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.js"></script>
</head>
<body>
<div id="dash"></div>
</body>
</html>
您可以修改C3的饼图源代码 或者通过CONFI gui,修改dom元素: onclick:function(d,i){console.log(“onclick”,d,i); }, 'i'是对应于该馅饼切片的dom svg元素。如果你可以破译svg中的值,你可能会想出一个方程式来修改它们: – miir
这就是其中一个元素的样子:' ' –
miir
我经历了d3.js教程,其中人正在创建甜甜圈聊天,在他使用transition()移动svg元素的同一示例中,他选择了路径(d3.selectAll “路径”)),并在其上应用转场来移动,我也想移动一段甜甜圈以便在鼠标悬停时向前弹出。在浏览器中,选择路径元素我改变比例值的形式尺度(1,1)来缩放(1.2,1.2)它只是帮助,但我不能以编程方式实现 –