问题描述
有人可以告诉我如何突出显示NVD3折线图中的某些坐标,具体取决于某些条件
,如果x轴值大于100,则突出显示该坐标。
Can somebody tell me how to highlight only certain coordinates in a NVD3 line graph depending upon some conditionlike if x axis value is above 100,highlight that coordinate.
请参阅以下图片:
此问题或类似问题已被提出,但我看不到任何答案。
提前致谢。
This question or similar question has been asked , but I see no answers.Thanks in advance.
推荐答案
NVD3 API不允许您这样做,因此您必须破解它并突出显示您自己感兴趣的数据点。一般方法是通过过滤数据为相关数据点创建圆圈:
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.
这篇关于如何仅突出显示NVD3折线图中的某些坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!