简体   繁体   中英

Unable to create On-Off graph with DyGraphs?

I have been using DyGraphs for a short time and have it displaying graphs well and seems to be working as expected with varying data from a temperature sensor. Where I am having trouble is trying to create and on-off type graph where I detect a switch is on or off. I have tried to look at writing a custom plotter but quickly halt as can't find any reference to what commands etc I can use.

As a simple case, lets say I have 4 data values named d1,d2,d3,d4. And each of these in order are 0,1,0,0 or off,on,off,off. What I don't want is the line going from d1,0 to d2,1 at an angle. I would like it to stay 0 until the change at d1, then go vertical to 1 and so on.

Any help to guide me in the right direction would be appreciated.

Try using the stepPlot option :

 g = new Dygraph( document.getElementById("graph"), "t,d1,d2,d3\\n" + "1,0,0,0\\n" + "2,1,0,0\\n" + "3,0,1,0\\n" + "4,0,0,1\\n" + "5,1,0,1\\n" + "6,0,1,0\\n" + "7,1,1,1\\n" + "8,0,0,0\\n", { legend: 'always', title: 'On/Off Chart', valueRange: [0, 1.5], stepPlot: true // <---- }); 
 #graph { width: 500px; height: 150px; } 
 <script src="http://dygraphs.com/dygraph-dev.js"></script> <div id="graph"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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