简体   繁体   English

d3.js图以绘制二进制数据

[英]d3.js graph to plot binary data

I am trying to create a graph which plots data from a log file, the data indicates if several switches are on or off, so the data line for them is 1 or 0 and this is logged over a 24 hour period. 我正在尝试创建一个从日志文件中绘制数据的图形,该数据指示多个开关是打开还是关闭,因此它们的数据行是1或0,并且记录了24小时。 What I am looking is the time scale (24 hour period) along the bottom, which I have done ok, and this is where I need the help, I need a horizontal bar for each of the data lines which spans the entire time scale but it would be two colours, one for when it is on (data =1) and another for when it is off. 我正在寻找的是底部的时间刻度(24小时周期),我已经确定了,这是我需要帮助的地方,我需要一条横跨整个时间刻度的数据线的水平条,但是这将是两种颜色,一种用于打开时(数据= 1),另一种用于关闭时。

I suspect I need to do check the data in the following section of code and the set the colour based on its value but how do I access the data here 我怀疑我需要检查以下代码部分中的数据,并根据其值设置颜色,但是如何在此处访问数据

  svg.append("path")      
    .attr("class", "line")
    .style("stroke", "red")
    .attr("stroke-width", 5)
    .attr("d", valuleline_heater1(data));

In this section I can access the data but can't control the colour 在本节中,我可以访问数据,但不能控制颜色

    var valuleline_heater1 = d3.svg.line()
            .x(function(d) { return x(d.dt); })
            .y(function(d) { return y(d.heater1); });

Can any one point me in the right direction, many thanks 谁能指出我正确的方向,非常感谢

A path is a single entity, so you can't style parts of if according to some data. 路径是单个实体,因此您无法根据某些数据设置if的样式。 What d3.svg.line does is create the string that describes the path (the d attribute of the path element), so it uses all the data to create a single element. d3.svg.line作用是创建描述路径的字符串( path元素的d属性),因此它将使用所有数据来创建单个元素。

If I understood correctly what you want, instead of using a path you should use a segmented line: draw n line segments (svg line elements) so that you can style each one individually, according to its datum. 如果我正确理解了您想要的内容,那么应该使用分段线代替使用路径:绘制n条线段(svg line元素),以便可以根据其基准分别设置每个样式。

You can take a look at this example , you'll see that it creates a path element for each datum. 您可以看一下此示例 ,您将看到它为每个基准创建了一个path元素。

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

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