[英]Return a JSON Object after clicking on donut Chart (c3js)
I use c3js in my web application, I have added a Donut Chart into my View and it all works fine ! 我在Web应用程序中使用了c3js ,我在视图中添加了甜甜圈图 ,并且一切正常!
But, when I want to retrieve the JSON object from the clicked zone, I receive an object of the type SVGPathElement after displaying it in the console, I try to convert it to JSON but doesn't work: 但是,当我想从单击区域中检索JSON对象时,在控制台中显示该对象后,我收到了SVGPathElement类型的对象,我尝试将其转换为JSON但不起作用:
How do I get the data from the clicked element? 如何从clicked元素中获取数据?
My code is similar to that : 我的代码类似于:
var chart = c3.generate({
data: {
columns: [
['data1', 30],
['data2', 120],
],
type : 'donut',
onclick: function (d, i) { console.log("onclick", d, i); },
onmouseover: function (d, i) { console.log("onmouseover", d, i); },
onmouseout: function (d, i) { console.log("onmouseout", d, i); }
},
donut: {
title: "Iris Petal Width"
}
});
You can send it using ajax 您可以使用ajax发送
var chart = c3.generate({
data: {
columns: [
['data1', 30],
['data2', 120],
],
type : 'donut',
onclick: function (d, i) {
$.ajax({
url:'your server php file',
headers:{/*some headers*/},
data:JSON.stringify(d),
}).then(function(data){
//do something in success
})
}
},
donut: {
title: "Iris Petal Width"
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.