Charts: Marker Position

Created on 23 Nov 2016  路  6Comments  路  Source: danielgindi/Charts

I've implemented a custom MarkerView, but every time the delegate function is called:

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
        let position = chartView.getMarkerPosition(highlight: highlight)
}

The value of the position is always (0.0, 0.0). But the marker is being designed:

Image of MarkerView

Most helpful comment

Yes, it seems that highlight.drawX and drawY always returns values (0.0, 0.0).

As mentioned @Rnorback you could use highlight.xPx & highlight.yPx. Marker position could be converted to any view like this:

let rectInTableView = chartView.convert(CGRect(x: highlight.xPx, y: highlight.yPx, width: 0, height: 0), to: tableView)

All 6 comments

    open func getMarkerPosition(highlight: Highlight) -> CGPoint
    {
        return CGPoint(x: highlight.drawX, y: highlight.drawY)
    }

Would you please debug highlight.drawX and drawY, to see what's the problem? I tried in ChartsDemo, it's fine.

so the way to get the markerPosition now seems to be by getting the hightlight.xPx and highlight.xPy. However, these values are given within the bounds of the chartView.

Yes, it seems that highlight.drawX and drawY always returns values (0.0, 0.0).

As mentioned @Rnorback you could use highlight.xPx & highlight.yPx. Marker position could be converted to any view like this:

let rectInTableView = chartView.convert(CGRect(x: highlight.xPx, y: highlight.yPx, width: 0, height: 0), to: tableView)

I guess you may have to debug why highlight.drawX is 0.0. In charts demo, I am seeing valid values.

Tested on ChartDemo with LineChart1ViewController.

Breakpoint at

  • (void)chartValueSelected:(ChartViewBase * __nonnull)chartView entry:(ChartDataEntry * __nonnull)entry highlight:(ChartHighlight * __nonnull)highlight

Result :
capture d ecran 2017-09-19 a 10 25 44

@jndefosse It's an old issue; are you breaking at the beginning?

            let x = high.x // get the x-position
            let y = high.y * Double(animator.phaseY)

            if x > chartXMax * animator.phaseX
            {
                continue
            }

            let trans = dataProvider.getTransformer(forAxis: set.axisDependency)

            let pt = trans.pixelForValues(x: x, y: y)

There is chance that x, y is 0 when chart just starts. You are welcome to debug, as I don't know the real issue. No update for quite a while, and Chart marker seems working all the time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aungbandlab picture Aungbandlab  路  4Comments

sjdevlin picture sjdevlin  路  3Comments

PrashantKT picture PrashantKT  路  3Comments

guanyanlin picture guanyanlin  路  3Comments

newbiebie picture newbiebie  路  3Comments