简体   繁体   English

如何在c3.js折线图中仅突出显示一个数据点?

[英]How to highlight only one datapoint in c3.js line graph?

Using point show as false hides all the data points . 使用point show作为false可以隐藏所有数据点
But what to do if I want to hide all but one datapoint. 但是,如果我想隐藏除一个数据点之外的所有数据点,该怎么办。

For Example, 例如,

 var chart = c3.generate({ data: { columns: [ ['data1', 30, 200, 100, 400, 150, 250], ['data2', 50, 20, 10, 40, 15, 25] ] } }); 

In the above line chart, how to highlight the data point where value is 100 and hide every other data point? 在上面的折线图中,如何突出显示值为100的数据点并隐藏其他所有数据点?

In C3, those circles have a class named c3-circle . 在C3中,这些圆具有名为c3-circle的类。 So, using a D3 selection, you can set the opacity based on the bound datum: 因此,使用D3选择,您可以基于绑定的基准设置不透明度:

var circles = d3.selectAll(".c3-circle")
    .style("opacity", function(d){
        return d.value === 100 ? 1 : 0;
    })

Thus, only the circle corresponding to 100 is visible. 因此,只有对应于100的圆圈可见。

Here is the demo: 这是演示:

 var chart = c3.generate({ data: { columns: [ ['data1', 30, 200, 100, 400, 150, 250], ['data2', 50, 20, 10, 40, 15, 25] ] } }); var circles = d3.selectAll(".c3-circle").style("opacity", function(d){ return d.value === 100 ? 1 : 0; }) 
 <script src="https://d3js.org/d3.v3.min.js"></script> <link rel="stylesheet" type="text/css" href="https://rawgit.com/masayuki0812/c3/master/c3.css"> <script src="https://rawgit.com/masayuki0812/c3/master/c3.js"></script> <div id="chart"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM