我试图从静态html SVG(使用动态值)切换到动态d3 SVG在骨干视图中。我目前正在使用模板(并希望保持它的某些其他属性),但不必(因为我可以用模板将这些属性重构为自己的视图)。使用骨干渲染d3 SVG的基本示例查看
任何人都有一个干净的快速示例,就像只有一个圆圈?
Backbone和我发现的d3最接近的版本是here,但这是我想要的,并且还没有足够的d3经验来理解函数调用和结构。
当前提供该问题的代码是在视图的渲染():
var pathFunction = d3.svg.line()
.x(function (d) {return d.x;})
.y(function (d) {return d.y;})
.interpolate("basis"); // bundle | basis | linear | cardinal are also options
//The Circle SVG Path we draw
var svgContainer = d3.select('#measure'+measure.cid);
var circle = svgContainer.append("g")
.append("path")
.data([circleStates[0]])
.attr("d", pathFunction)
.attr("class", "circle");
var compiledTemplate = _.template(this.representations[this.currentRepresentation], measureTemplateParamaters);
$(this.el).find('.addMeasure').before(compiledTemplate);
基本上我试图绘制路径的圈子,通过已经计算的点来定义。我只是不知道如何得到它传递给任何模板或通过Backbone.View
控制台错误时,“珠”是在this页面选择的DOM:
Error: Problem parsing d="function line(data) {
var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
function segment() {
segments.push(" jquery.js:6326
jQuery.extend.clean jquery.js:6326
jQuery.buildFragment jquery.js:6165
jQuery.fn.extend.domManip jquery.js:5975
jQuery.fn.extend.before jquery.js:5795
(anonymous function) measuresView.js:227
_.each._.forEach underscore.js:78
Backbone.View.extend.render measuresView.js:133
Backbone.View.extend.changeMeasureRepresentation measuresView.js:90
triggerEvents backbone.js:96
Backbone.Events.trigger backbone.js:187
Backbone.View.extend.cycle wholeMeasureRepresentationView.js:46
jQuery.event.dispatch jquery.js:3059
elemData.handle.eventHandle jquery.js:2677
这是全错误,并且与我的代码不匹配,导致我相信这看起来好像是在尝试使用d3的函数并进行渲染,而不是我期望的d3返回。堆栈跟踪最终将我导回到传入的编译模板((anonymous function) measuresView.js:227
),这就是我想要弄清的,如何将d3 SVG传递到模板中。
您发布的这个示例非常完整。你错过了什么部分?如何呈现模板,然后使用d3.js注入内容? – 2013-04-29 19:00:08
你必须发布一些更多的代码,并且除了可以复制问题的代码之外,还可以包含一个jsFiddle。 – 2013-04-29 19:14:04
我已经尽可能地在这个[fiddle](http://jsfiddle.net/chrisfrisina/6a6da/)中最小化文件,但是,我不知道如何去除require.js,我不认为该模板正确传递为像'!text'版本那样的字符串。然而,我确实对网站[这里](http://compthink.cs.vt.edu:3000)进行了更改,因此您可以看到该错误。只需将“度量表示法”切换到Bead,并且您可以在控制台中看到错误。对于完整的代码,你可以看到它[这里](http://bit.ly/11SElsU)。 THX为您提供帮助!尝试替换为[this](http://jsfiddle.net/chrisfrisina/6sYAY/) – 2013-04-29 20:11:47