简体   繁体   English

D3图形未显示

[英]D3 Graph Not Showing Up

I have been digging at this problem for the past few hours, but I can't seem to get the step plot to appear in the jfiddle below 在过去的几个小时中,我一直在研究这个问题,但似乎无法在下面的jfiddle中显示步骤图

http://jsfiddle.net/uk8t6mtg/1/ http://jsfiddle.net/uk8t6mtg/1/

I suspect it is because I am misunderstanding how to use an x-axis with times conceptually. 我怀疑这是因为我误解了如何在概念上使用x轴。

I am trying to make a graph where I have data like: 我正在尝试制作一个具有以下数据的图形:

data = {"step_plot_3": {"x_axis": ["4-Jun-07", "5-Jun-07", "6-Jun-07", "7-Jun-07", "8-Jun-07"], "y_axis": [0.32322222222152003, 9.7200555555434001, 0.8200000000001999, 0.27433333333332, 1.0541111111102599]}}

where the dates may not be sequential but will be equally far apart. 日期可能不连续,但间隔相等。 The y-values correspond to hours and are represented by a step plot. y值对应于小时,并由阶梯图表示。

The code comes largely from a D3.js example with additional modifications I have made myself. 该代码主要来自D3.js示例,并对我自己进行了其他修改。

Example: 例:

http://bl.ocks.org/mbostock/3883245 http://bl.ocks.org/mbostock/3883245

Any advice on how to debug this issue would be largely appreciated. 任何有关如何调试此问题的建议将不胜感激。

In your JS console or in the DOM, you'll see a path with an invalid value for d, "MNaN,447.6.....". 在您的JS控制台或DOM中,您将看到路径的d值为无效值“ MNaN,447.6 .....”。 An incorrect value was going into the xAxis scaling function. xAxis缩放函数输入了错误的值。 If you change line 48 of the fiddle to: return parseDate(d); 如果将小提琴的第48行更改为: return parseDate(d); You'll see a valid path rendered. 您会看到一个有效的路径。

Also you'd need to style the path to remove the fill and add a stroke color. 另外,您还需要设置路径样式以删除填充并添加笔触颜色。 Something like: 就像是:

.line {
    fill:none;
    stroke: red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM