MPAndroidChart MarkerView

My intention is to find a specific point in the MPAndroidChart line chart, and then display a marker to highlight the point after clicking the button. The above example is where the marker is displayed only after touching an event, which in my case is different. I tried the code below, but to no avail, can someone please teach me, I would appreciate it.

Highlight h = new Highlight((int) valIndex, linechart2.getData().getDataSetCount()); linechart2.highlightValue(h, true); mv2.refreshContent2(valueYAxis.get((int) valIndex), h); linechart2.getMarkerView(); linechart2.setDrawMarkerViews(true); linechart2.getData().setHighlightEnabled(true); // RefreshChart(); linechart2.invalidate(); 
+7
android mpandroidchart
source share
2 answers

You can easily extract values โ€‹โ€‹programmatically using one of the following methods for your Chart object:

  • highlightValues(Highlight[] highs) : highlights the values โ€‹โ€‹at given indices in these datasets. Provide a null or empty array to cancel all selections.
  • highlightValue(int xIndex, int dataSetIndex) : selects the value at the given x-index in this data set. Provide -1 as x-index or dataSetIndex to deselect all.

All this in the wiki .

+1
source share

I go through the wiki when you linked, and even more than that, I tried the code below, different from the previous one,

 Highlight h = new Highlight((int) valIndex, 0); linechart2.highlightValue(h); mv2.refreshContent2(valueYAxis.get((int) valIndex), h); linechart2.getMarkerView(); linechart2.setDrawMarkerViews(true); linechart2.getData().setHighlightEnabled(true); // RefreshChart(); linechart2.invalidate(); 

the result is still unsuccessful, the marker never appears. I am doing research in a single step according to your example code code. It shows after touching the event, the program immediately goes to refreshContent and goes to the offset function x and y after that, and the marker just pops up. But my script, which I mentioned earlier, will not touch the touch event, but presses a button where my graph will be displayed and indicate, indicating the location point relative to the time that the end user is looking for. So I manually added refreshContent2 (the same as the refreshContent function in the MarkerView class) to emulate the process, but after that I found that it never goes and gets the offset function x, y, which is different from your example. Viewing a marker never appears, because of this, am I suspicious?

0
source share

All Articles