Skip to content
Philipp Jahoda edited this page Aug 20, 2016 · 5 revisions

Since release v3.0.0, markers (popup views) in the chart are represented by the IMarker interface.

###IMarker interface

This interface allows you to create custom marker views displayed at highlighted entries in your chart. The methods provided by the interface look as follows:

public interface IMarker {

    /**
     * @return The desired (general) offset you wish the IMarker to have on the x- and y-axis.
     *         By returning x: -(width / 2) you will center the IMarker horizontally.
     *         By returning y: -(height / 2) you will center the IMarker vertically.
     */
    MPPointF getOffset();

    /**
     * @return The offset for drawing at the specific `point`. This allows conditional adjusting of the Marker position.
     *         If you have no adjustments to make, return getOffset().
     *
     * @param posX This is the X position at which the marker wants to be drawn.
     *             You can adjust the offset conditionally based on this argument.
     * @param posY This is the X position at which the marker wants to be drawn.
     *             You can adjust the offset conditionally based on this argument.
     */
    MPPointF getOffsetForDrawingAtPos(float posX, float posY);

    /**
     * This method enables a specified custom IMarker to update it's content every time the IMarker is redrawn.
     *
     * @param e         The Entry the IMarker belongs to. This can also be any subclass of Entry, like BarEntry or
     *                  CandleEntry, simply cast it at runtime.
     * @param highlight The highlight object contains information about the highlighted value such as it's dataset-index, the
     *                  selected range or stack-index (only stacked bar entries).
     */
    void refreshContent(Entry e, Highlight highlight);

    /**
     * Draws the IMarker on the given position on the screen with the given Canvas object.
     *
     * @param canvas
     * @param posX
     * @param posY
     */
    void draw(Canvas canvas, float posX, float posY);
}

###Creating a MarkerView

In order to create your custom marker view, you need to create a new class that implements the IMarker interface:

public class YourMarkerView implements IMarker { ... }

What you return from the methods provided by the interface depends on your personal requirements. Have a look at the above shown documentation of the methods for better understanding.

###Getting / Setting the Marker

In order to set your marker to the chart, use the setMarker(...) method:

IMarker marker = new YourMarkerView();
chart.setMarker(marker);

To access an existing marker set to the chart, use the getMarker() method:

IMarker marker = chart.getMarker();

###Predefined Markers

###Legacy MarkerView

In versions prior to v3.0.0, the MarkerView class was responsible for drawing markers at highlighted positions in the chart. For detailed information regarding this class, please visit the old MarkerView wiki page.

Clone this wiki locally