conditional fill in d3.js for area chart

后端 未结 1 845
面向向阳花
面向向阳花 2021-02-14 03:25

I have an area graph (supposed to represent a time series). I want to color the graph based on the y value such that for regions where the y > c it is one color and for the are

1条回答
  •  终归单人心
    2021-02-14 03:51

    Change the way you add the areas to something like

        vis.selectAll("path").data(mpts).enter().append("svg:path")
            .attr("class", "area")
            .attr("d", area)
            .attr("fill", function(d) { return (d.val > c ? "orange" : "yellow"); });
    

    0 讨论(0)
提交回复
热议问题