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

前端 未结 1 730
挽巷
挽巷 2021-01-12 21:05

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

相关标签:
1条回答
  • 2021-01-12 21:22

    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() {
                }
            });
    
    0 讨论(0)
提交回复
热议问题