本文介绍了具有3个数据集的折线图的MPAndroidChart多个工具提示/标记视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在为我的应用程序使用 MPAndroidChart .在一种情况下,我在一个折线图中显示了三个数据集,当我单击图形上的线时,一次只能显示一个工具提示.而是根据十字线的位置,我想显示所有三个数据集的单独工具提示.

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.

推荐答案

请尝试以下&让我知道您的反馈意见

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() {
            }
        });

这篇关于具有3个数据集的折线图的MPAndroidChart多个工具提示/标记视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 11:13