javascript - IF-statement stroke in a line diagram using d3.js -
i've drawn graph using data out of database, , want line turn red when number in database gets higher 500 (like below). unfortunately doesn't work way, , i've tried other stuff, no succes.
though dashed line work using code .style("stroke-dasharray", ("3, 3"))
my question: possible let stroke color turn red when y value gets higher point in d3.js?
// adds svg canvas var svg = d3.select("body") // explicitly state svg element go on web page (the 'body') .append("svg") // append 'svg' html 'body' of web page .attr("width", width + margin.left + margin.right) // set 'width' of svg element .attr("height", height + margin.top + margin.bottom)// set 'height' of svg element .append("g") // append 'g' html 'body' of web page .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // in place actual area graph d3.json("php/data2.php", function(error, data) { // go data folder (in current directory) , read in data.tsv file data.foreach(function(d) { // data values carry out following d.date = parsedate(d.date); // parse date set format (see parsedate) d.close = +d.close; // makesure d.close number, not string }); // scale range of data x.domain(d3.extent(data, function(d) { return d.date; })); // set x domain wide range of dates have. y.domain([0, d3.max(data, function(d) { return d.close; })]); // set y domain go 0 maximum value of d.close // add valueline path. svg.append("path") // append valueline line 'path' element .attr("class", "line") // apply 'line' css styles path .style("stroke-dasharray", ("3, 3")) .attr("d", valueline(data)); // call 'valueline' finction draw line // add x axis svg.append("g") // append x axis 'g' (grouping) element .attr("class", "x axis") // apply 'axis' css styles path .attr("transform", "translate(0," + height + ")") // move drawing point 0,height .call(xaxis); // call xaxis function draw axis // add y axis svg.append("g") // append y axis 'g' (grouping) element .attr("class", "y axis") // apply 'axis' css styles path .call(yaxis); // call yaxis function draw axis
your data not binded correctly element, it's difficult tell without complete code. need...
svg.selectall("path") .data(data) .enter() .append("path") .attr("class", "line") .attr("stroke", function(d) {..});
you can see simplified demonstration of code here: http://jsfiddle.net/duopixel/v84fz/
Comments
Post a Comment