我是新手,我正在尝试将字符串传递给函数或其他任何东西。
在数据和项目下面有一些文字。
这是一个名为index.js的文件。更进一步的是BubbleInfo。将我的文本导入BubbleInfo的语法是什么,以便将其传递给函数。我已经尝试了几天和几天,无法获得正确的语法来获取文本。我总是得到错误或未定义。
$(document).ready(function () {
var bubbleChart = new d3.svg.BubbleChart({
supportResponsive: true,
//container: => use @default
size: 600,
//viewBoxSize: => use @default
innerRadius: 600 / 3.5,
//outerRadius: => use @default
radiusMin: 50,
//radiusMax: use @default
//intersectDelta: use @default
//intersectInc: use @default
//circleColor: use @default
data: {
items: [
{text: "Work History", count: "3"},
{text: "Projects", count: "4"},
{text: "Education", count: "3"},
{text: "Work Locations", count: "4"},
],
eval: function (item) {return item.count;},
classed: function (item) {return item.text.split(" ").join("");}
},
plugins: [
{
name: "central-click",
options: {
text: ("See more detail"),
BubbleInfo: (**data.items.text**),
style: {
"font-size": "12px",
"font-style": "italic",
"font-family": "Source Sans Pro, sans-serif",
//"font-weight": "700",
"text-anchor": "middle",
"fill": "white"
},
attr: {dy: "65px"},
centralClick: function() {
// window.alert("Here is details!!");
}
}
},
{
name: "lines",
options: {
format: [
{// Line #0
textField: "count",
classed: {count: true},
style: {
"font-size": "28px",
"font-family": "Source Sans Pro, sans-serif",
"text-anchor": "middle",
fill: "white"
},
attr: {
dy: "0px",
x: function (d) {return d.cx;},
y: function (d) {return d.cy;}
}
},
{// Line #1
textField: "text",
classed: {text: true},
style: {
"font-size": "14px",
"font-family": "Source Sans Pro, sans-serif",
"text-anchor": "middle",
fill: "white"
},
attr: {
dy: "20px",
x: function (d) {return d.cx;},
y: function (d) {return d.cy;}
}
}
],
centralFormat: [
{// Line #0
style: {"font-size": "50px"},
attr: {}
},
{// Line #1
style: {"font-size": "30px"},
attr: {dy: "40px"}
}
]
}
}]
});
});
答案 0 :(得分:0)
如果我正确理解了您的问题而您只想要一个包含所有文本字段的数组,则只需使用Array.prototype.map
。
var data = {
items: [{
text: "Work History",
count: "3"
}, {
text: "Projects",
count: "4"
}, {
text: "Education",
count: "3"
}, {
text: "Work Locations",
count: "4"
}]
};
var texts = data.items.map(function(item) {
return item.text;
}); //["Work History", "Projects", "Education", "Work Locations"]
var bubbleChart = new d3.svg.BubbleChart({
///...
data: data, //Add methods to data declaration above if needed
plugins: [{
//...
options: {
BubbleInfo: texts
}
}]
});