Javascript 流星星图不';我不能完全露面
下面是我使用Meteor在网页上呈现pieChart的JS代码。我遇到的问题是,除了图表显示在图例和标签上,但我们看不到饼图(它只是空的)之外,这段代码几乎可以工作。javaScript代码如下所示 [我无法在此发布图像]Javascript 流星星图不';我不能完全露面,javascript,mongodb,d3.js,meteor,reactiveui,Javascript,Mongodb,D3.js,Meteor,Reactiveui,下面是我使用Meteor在网页上呈现pieChart的JS代码。我遇到的问题是,除了图表显示在图例和标签上,但我们看不到饼图(它只是空的)之外,这段代码几乎可以工作。javaScript代码如下所示 [我无法在此发布图像] if (Meteor.isClient) { Template.pienvd3.rendered = function() { nv.addGraph(function() { var pchart = nv.models.pieC
if (Meteor.isClient) {
Template.pienvd3.rendered = function() {
nv.addGraph(function() {
var pchart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.showLabels(true);
d3.select("#piechart svg")
.datum(pieVar.find().fetch())
.transition().duration(350)
.call(pchart);
return pchart;
});
};}
这是我在MongoDB的收藏,名为“pienvd3”
我出版了这本藏书,并宣布了它
Meteor.publish(null, function () {
return pieVar.find();
});
pieVar = new Meteor.Collection("pienvd3");
pieVar.allow({
insert: function () {
return true;
},
update: function () {
return true;
},
remove: function () {
return true;
}
});
现在我真的无法理解到底是什么问题。
附言:我需要让这张图表反应,我已经包括了d3所有必要的软件包。当我刷新页面时,甚至这个图像也消失了,表示找不到数据
谢谢您在功能之外更改退货
Template.pienvd3.rendered = function() {
nv.addGraph(function() {
var pchart = nv.models.pieChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.showLabels(true);
d3.select("#piechart svg")
.datum(pieVar.find().fetch())
.transition().duration(350)
.call(pchart);
});
return pchart;
};}
就像@johnytop说的,如果你有autopublish
package-remove,一定要订阅收藏
Meteor.subscribe('pienvd3');
Router.route('/testPage', {name: 'testPage'});
this.route('testPage', {
path: '/testPage',
waitOn: function(){
return Meteor.subscribe("pieVar");
},
data: function(){
return return pieVar.find();;
}
});
我也不知道为什么,但是您正在发布Null
数据
换成这个
Meteor.publish('pieVar' function () {
return pieVar.find();
});
在lib
文件夹中声明此集合,如下/lib/collections.js
pieVar = new Meteor.Collection("pieVar");
可能是由于某些原因,您在客户端没有数据
lib
文件夹)谢谢大家。。。。不需要对代码进行任何更正。我通过更改文档的
\u id
来实现它。我给了我自己的\u id
而不是mongoldb中的自动生成的我也得到了范围错误:超过了最大调用堆栈大小。
作为控制台中的错误,它应该是nv.addGraph函数
,你在使用什么包
,我能看到文档吗?如果你上传一个这样的Meteopad就好了
pieVar = new Meteor.Collection("pieVar");