Flat JSON with multiple data for multi line chart

16 views
Skip to first unread message

Petar

unread,
May 23, 2017, 4:43:26 AM5/23/17
to d3-js
Hello,

I have relatively simple JSON structure that I would like to use for multi line d3 chart.

data=[
{
"sensid0_valhi": 40,
"sensid0_vallow": 45,
"time": "2017-04-25T21:05:12"
},
{
"sensid0_valhi": 70,
"sensid0_vallow": 75,
"time": "2017-04-25T21:05:13"
},
{
"sensid0_valhi": 80,
"sensid0_vallow": 85,
"time": "2017-04-25T21:05:14"
}]

I need to bind 2 set of data from JSON: first pare time and sensid0_vallow and second pare time and sensid0_valhi.
How can I change my svg.line to create binding for 2 lines in graph:
What I have done so far I think is not OK:
var line = d3.svg.line()
.x(function (d) {
return x(d.vrijeme);
})
.y(function (d,i) {
return y(d.value);
})
.interpolate("linear");

var chartBody = svg.append("g")
.attr("clip-path", "url(#clip)");

chartBody.append("svg:path")
.datum(data)
.attr("class", "line")
.attr("d", line);

thanks
Reply all
Reply to author
Forward
0 new messages