在移动到服务器主机之前,如何处理代码中的文件路径?(How do I handle file paths in my code before moving to server host?)
在我的网页中,我引用了js和图像,如下所示:“../../Content/Images/”文件名“
在我的代码中,如果我参考上面的文件,它不起作用,所以我必须写:“c:/ miscfiles /”filename“
1-为什么第一个参考在网页上工作,而不在代码中? 2 - 我应该如何在代码中引用文件路径,以便在移动到服务器时不必重新编码?
In my webpages I have references to js and images as such: "../../Content/Images/"Filename"
In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename"
1-Why does the first reference work on webpages and not within the code? 2-How should i reference file paths in code so that I will not have to recode when moving to server?
原文:https://stackoverflow.com/questions/1727320
最满意答案
感谢JSBob与我合作。 我有它的工作:
function updateGraphs(newData){
d3.selectAll("svg").each(function(d, i){ eachRace = d.values; svg = d3.select(this); yMax = d3.max(eachRace, function(d) { return d[newData]; }); yScale = d3.scale.linear().domain([0, yMax*1.25]).range([height/8, 0]).nice(); yAxis = d3.svg.axis().scale(yScale).orient("left").ticks(5); console.log(yMax); line = d3.svg.line() .x(function (d) { return x(d.date); }) .y(function (d) { return yScale(d[newData]); }) svg.transition().duration(1000).select(".line") .attr("id", function(d) { return d.key ;}) .attr('class', 'line') .attr('opacity', .8) .attr('d', function(d) { return line(d.values); }); svg.transition().duration(1000).select(".y.axis") .call(yAxis); }); }
Thanks JSBob for working with me. I've got it working with:
function updateGraphs(newData) {
d3.selectAll("svg").each(function(d, i){ eachRace = d.values; svg = d3.select(this); yMax = d3.max(eachRace, function(d) { return d[newData]; }); yScale = d3.scale.linear().domain([0, yMax*1.25]).range([height/8, 0]).nice(); yAxis = d3.svg.axis().scale(yScale).orient("left").ticks(5); console.log(yMax); line = d3.svg.line() .x(function (d) { return x(d.date); }) .y(function (d) { return yScale(d[newData]); }) svg.transition().duration(1000).select(".line") .attr("id", function(d) { return d.key ;}) .attr('class', 'line') .attr('opacity', .8) .attr('d', function(d) { return line(d.values); }); svg.transition().duration(1000).select(".y.axis") .call(yAxis); }); }
相关问答
更多-
d3使用两个数据集进行转换(d3 transitions using two datasets)[2022-07-24]
感谢NoahRC给了我一个解决方案。 第一个代码块应该在循环之前定义“i”的函数: var tween = function(i){ arcs.transition() .delay((slideDuration + spinDuration) * i) .duration(spinDuration) .ease("cubic-out") .attrTween("transform", function (){ return d3.interpolateString("rota ... -
D3多力导向图(D3 Multiple Force Directed Graphs)[2022-09-13]
你需要在你传递给d3.json但不在它之外的回调函数(错误,图形)中设置svg 原因:您传递给d3.json的回调函数是异步调用的,即当您循环遍历eventss数组时,每次迭代它将无法正常运行。 在循环结束后,似乎所有4个回调都返回,因此svg被设置为它在该循环中的最后一个值,因此所有内容都被添加到该svg元素中。 You need to set svg within the callback function(error, graph) you pass to d3.json and not outsid ... -
我认为快速平滑动画的最佳选择是放弃过渡并使用window.requestAnimationFrame 。 我认为它看起来像这样: function tick() { data[current_i] = get_next_data_point(); current_i = (current_i + 1) % window_width_in_samples; path.data(data).attr("d", line); window.requestAnimationFr ...
-
在arcTween返回arc(d)时: function arcTween(transition, newAngle) { transition.attrTween("name", function(d) { var interpolate = d3.interpolate(d.endAngle, newAngle); return function(t) { d.endAngle = interpolate(t); ...
-
您的脚本都声明了名为'svg'的全局变量,然后在加载文件后在回调中引用此全局变量。 如果检查图形,您将看到它们实际上都在同一个SVG元素上,而线图应该在的SVG元素是空的。 您需要在第二个脚本中重命名变量,以使它们的名称与第一个脚本中的变量不同。 Both your scripts declare global variables named 'svg' and then reference this global variable in the callback after the file is loa ...
-
D3转换为多个图形(D3 transitions with multiple graphs)[2023-06-05]
感谢JSBob与我合作。 我有它的工作: function updateGraphs(newData){ d3.selectAll("svg").each(function(d, i){ eachRace = d.values; svg = d3.select(this); yMax = d3.max(eachRace, function(d) { return d[newData]; }); yScale = d3.scale.linear().domain([0, yM ... -
d3 mutliple线图(d3 multiple line graphs)[2023-04-28]
这个片段有问题: data.forEach(function (d) { d.date = parseTime(d.date); d.units = parseInt(d.units); }); tdata.forEach(function (d) { d.date = parseTime(d.date); d.units = parseInt(d.units); }); tdata和data是包含对相同对象的引用的数组。 所以第二个forEach然后作用于相同的对象并且parseTime ... -
那么你在我之前的答案中发现了一个错误:) 正如您所说,问题是保存的值未正确更新。 那是因为回调内部不再引用path DOM元素。 修复很简单 - 在上面的级别的函数中保存this的引用并使用该引用: function arcTweenUpdate(a) { var i = d3.interpolate({x: this.x0, dx: this.dx0}, a); var that = this; return function(t) { var b = i(t); that.x ...
-
因此,转换多个属性是这个问题的简单部分。 就像常规选择一样,您可以在转换时一次设置多个属性: selectedNodeCircles.transition().duration(500) .attr("r", function(d){ return rRange(d.rSize); }) .attr("stroke", 'red'); 这将转换您的半径和线条颜色。 转换是DOM元素的属性(在本例中为圆圈),它将根据您的喜好转换尽可能多的DOM属性。 要记住的是每个DOM元素上只有一个转换对 ...
-
滞后可以很容易地解释。 你忘了改变这个: for (var i = 0; i < dataSet.length; ++i) simulation.tick(); 在我的原始代码中,我有大约190个国家。 但是,您有440个数据点,这需要更多时间进行计算。 因此,只需将tick的调用次数更改为100到300之间的值: for (var i = 0; i < 150; ++i) simulation.tick(); // ^-------- tweak this numbe ...