最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide some graphic elements, c3js, without unloading data - Stack Overflow

programmeradmin3浏览0评论

Is it possible to hide certain lines, bars and other graphic elements from a c3js chart, without unloading or hiding data?

I wish to keep that data in the tooltip but hide some graphic elements. Hover over one bar and see data for other hidden bars.

I know about the hide method - chart.hide(['data2', 'data3']); - but this also deletes the data from the tooltip.

My question is not discussed in the documentation it seems.

A similar issue in November was not solved.

I don't have any code right now - just looking for an alternative to making a custom tooltip.

Thanks

Is it possible to hide certain lines, bars and other graphic elements from a c3js chart, without unloading or hiding data?

I wish to keep that data in the tooltip but hide some graphic elements. Hover over one bar and see data for other hidden bars.

I know about the hide method - chart.hide(['data2', 'data3']); - but this also deletes the data from the tooltip.

My question is not discussed in the documentation it seems.

A similar issue in November was not solved.

I don't have any code right now - just looking for an alternative to making a custom tooltip.

Thanks

Share Improve this question edited May 23, 2017 at 10:28 CommunityBot 11 silver badge asked Dec 30, 2014 at 6:03 JasTonAChairJasTonAChair 1,9781 gold badge19 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

One easy solution is to use CSS display property for the chart svg elements like:-

http://jsfiddle/chetanbh/j9vx0dmg/

var chart = c3.generate({
  data: {
    columns: [
        ['data1', 100, 200, 150, 300, 200],
        ['data2', 400, 500, 250, 700, 300],
    ]
  }
});

In the above c3js chart example a line chart is rendered with two lines.

Each line is a Path svg element under a Group element. These group elements will get class attribute values like 'c3-target-data1' and 'c3-target-data2'.

Taking advantage of this we can use CSS like:-

.c3-target-data2 {
    display: none;
}

to hide the entire 'data2' in the chart, but tooltip will continue to show the data for 'data2'.

Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论