Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart MarkerView

I have intention on looking for a specific point in a line chart of MPAndroidChart and then display the the marker to highlight the point after a button is hit. The example given is where the marker is only displayed after touching event which is different in my case. I tried code below but to no avail, can some one please teach me I would appreciate.

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();
like image 497
Han Whiteking Avatar asked Dec 23 '15 07:12

Han Whiteking


2 Answers

You can easily highlight values programmatically by using one of the following methods on your Chart object:

  • highlightValues(Highlight[] highs): Highlights the values at the given indices in the given DataSets. Provide null or an empty array to undo all highlighting.
  • highlightValue(int xIndex, int dataSetIndex): Highlights the value at the given x-index in the given DataSet. Provide -1 as the x-index or dataSetIndex to undo all highlighting.

It's all in the wiki.

like image 57
Philipp Jahoda Avatar answered Sep 28 '22 09:09

Philipp Jahoda


the makerview will show when the point is highlighted, so you can try this

Highlight h = new Highlight((int) valIndex, 0);
mv2.refreshContent2(valueYAxis.get((int) valIndex), h);
linechart2.setMarker(mv2);
linechart2.highlightValue(h);
like image 27
HeyDacy Avatar answered Sep 28 '22 10:09

HeyDacy