【发布时间】:2015-10-28 11:51:10
【问题描述】:
我正在探索 c3.js,我创建了一个甜甜圈图,这很简单,接下来我想做的是在鼠标悬停上我想扩展/缩放/弹出那个重点部分,这个功能我们可以在d3pai. 中看到,但我试图纯粹使用 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的饼图源码...或者通过配置修改dom元素: onclick: function (d, i) { console.log("onclick", d, i); },
i是对应于饼图的 dom svg 元素。如果您可以破译 svg 中的值是什么,您可能会想出一个方程式来修改它们: -
这是其中一个元素的样子:
<path class=" c3-shape c3-shape c3-arc c3-arc-virginica" transform="" d="M7.154998924018411e-15,-116.85A116.85,116.85 0 1,1 -45.11686019075751,107.78864238187454L0,0Z" style="fill: rgb(148, 103, 189); cursor: pointer; opacity: 1;"></path> -
我浏览了 d3.js 教程,其中一个人正在创建甜甜圈聊天,在同一个示例中,他使用 transition() 移动 svg 元素,他选择了路径 (d3.selectAll("path")) ,并在其上应用过渡以移动,我还想移动一段甜甜圈以在鼠标悬停时向前弹出。在浏览器中,选择路径元素我将比例值从比例(1,1)更改为比例(1.2,1.2)它只是帮助但我无法以编程方式实现
-
这正是我想要在 c3 link 中实现的目标
标签: c3.js