我試圖從靜態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