MPAndroidChart multiple tooltips / markers for line chart with 3 datasets

I am currently using MPAndroidChart for my application. In one scenario, I am displaying three datasets on one line, and when I click on a row in the graph, I can only show one hint at a time. Instead of basing on the position of the cross hair, I would like to show an individualized hint for all three datasets.

I have asked many other questions here and I could not find what I was looking for. This is a sample screenshot of my required output. I would like to know if this is possible and any help is greatly appreciated. Example graph

+3


source to share


1 answer


Please try the solution below and 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() {
            }
        });

      

+6


source







All Articles