MPAndroidChart multiple tooltip/marker view for linechart with 3 data sets

拟墨画扇 提交于 2019-12-07 10:29:53

问题


I am currently using MPAndroidChart for my application. In one scenario, I show three datasets within one linechart and when I click on the line on the graph, I get to show only one Tooltip at a time. Instead based on the cross hair position, I would like to show individual tooltip for all three datasets.

I have gone through many other questions here and I couldn't find exactly what I am looking for. This is a sample screenshot of my required output. I would like to know if this is possible and any help is much appreciated.


回答1:


Please try with the solution below & let me know your feedback

lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, Highlight h) {

                Highlight highlight[] = new Highlight[lineChart.getData().getDataSets().size()];
                for (int j = 0; j < lineChart.getData().getDataSets().size(); j++) {

                    IDataSet iDataSet = lineChart.getData().getDataSets().get(j);

                    for (int i = 0; i < ((LineDataSet) iDataSet).getValues().size(); i++) {
                        if (((LineDataSet) iDataSet).getValues().get(i).getX() == e.getX()) {
                            highlight[j] = new Highlight(e.getX(), e.getY(), j);
                        }
                    }

                }
                lineChart.highlightValues(highlight);
            }

            @Override
            public void onNothingSelected() {
            }
        });


来源:https://stackoverflow.com/questions/45245507/mpandroidchart-multiple-tooltip-marker-view-for-linechart-with-3-data-sets

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