javascript - How to color values greater than particular values in Histogram -


i have plotted histogram chart using d3 in have called values using json. want color values greater value.

d3.json('stk.json', function (data) {             // have space around items.           data =   $.each(data.stackoverflow,function(i,stack){                   return {bucket: stack.x1, n: stack.y};                   });                 x.domain(data.map(function (d) { return d.x1; }));         y.domain([0, d3.max(data, function (d) { return d.y; })]);      svg.append("g")         .attr("class", "axis")         .attr("transform", "translate(0, "+(height-pad)+")")         .call(xaxis);      svg.append("g")         .attr("class", "axis")         .attr("transform", "translate("+(left_pad-pad)+", 0)")         .call(yaxis);      svg.selectall('rect')         .data(data)         .enter()         .append('rect')         .attr('class', 'bar')         .attr('x', function (d) { return x(d.x1); })         .attr('width', x.rangeband())         .attr('y', height-pad)         .transition()         .delay(function (d) { return d.x1*20; })         .duration(800)         .attr('y', function (d) { return y(d.y); })         .attr('height', function (d) { return height-pad - y(d.y); })         .style("fill", function(d) { return color(d.y); });  }); 

could me it.

your answer right there on lien

.style("fill", function(d) { return color(d.y); });

just provide logic in side of function , make sure return appropriate color example lets want bars on 5 red do

.style("fill", function(d) { return d.y>5 ? '#ff0000' : color(d.y); });

hope helps


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -