Hide some graphic elements, c3js, without unloading data

烈酒焚心 提交于 2020-01-02 04:46:13

问题


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


回答1:


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

http://jsfiddle.net/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.



来源:https://stackoverflow.com/questions/27700379/hide-some-graphic-elements-c3js-without-unloading-data

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