How to highlight only certain coordinates in NVD3 line graph?

[亡魂溺海] 提交于 2019-12-02 21:26:08

问题


Can somebody tell me how to highlight only certain coordinates in a NVD3 line graph depending upon some condition like if x axis value is above 100,highlight that coordinate.

please see the image at :http://i.stack.imgur.com/AHJaK.jpg

This question or similar question has been asked , but I see no answers. Thanks in advance.

How to highlight a point on a Simple Line Chart in NVD3?


回答1:


The NVD3 API doesn't allow you do to that, so you have to "hack" it and highlight the data points you're interested in yourself. The general approach is to create the circles for the relevant data points by filtering the data:

var data = d3.select('#chart svg').datum();
        d3.select('.nv-groups')
            .selectAll("circle.myPoint")
            .data(data.filter(function(d) { return d.y > 3000; }))
            .enter().append("circle").attr("class", "myPoint")
            .attr("cx", function(d) { return chart.xAxis.scale()(d.x); })
            .attr("cy", function(d) { return chart.yAxis.scale()(d.y); })
            .attr("r", 5);

Incomplete demo for the first series in the data here.



来源:https://stackoverflow.com/questions/30039550/how-to-highlight-only-certain-coordinates-in-nvd3-line-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!