Search code examples
iosswiftchartsios-charts

highlightValue not working in chart with CombinedChartView :: Display marker programmatically is not working :: ChartIssue :: iOS Swift :: DanielGindi


Here is what i am doing!

chart.highlightValue(x: timeStampValue, dataSetIndex: totalCount)

==> In the above line, timeStampValue is x axis value which i have set while filling up the array. totalCount is total count of array of data which i am displaying in chart.

What i need to achieve is

When chart screen comes up, i need to display marker by default and for that, i am using "highlightValue" method of chart which is not working.

Please let me know the solution to show marker by default programatically.

NOTE: I am using marker whose UI is custom which is working fine when i tap manually at point in chart:

let marker = CustomMarkerView.viewFromXib()!
marker.chartView = chart
chart.marker = marker
chart.drawMarkers = true

Library used : https://github.com/danielgindi/Charts

Chart Data set :

let data = CombinedChartData()
data.lineData = LineChartData(dataSets:[viewModel.lineChartDataSet, viewModel.emptylineChartDataSet])
data.lineData.highlightEnabled = true
viewModel.lineChartDataSet.highlightColor = AssetsColor.highlightedColor.color
        viewModel.lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = false
viewModel.lineChartDataSet.highlightLineDashPhase = 2
viewModel.lineChartDataSet.highlightLineDashLengths = [5, 2.5]

Solution

  • chart.highlightValue(x: timeStampValue, dataSetIndex: 0, dataIndex: 0)
    

    When i added 1 more parameter which is dataIndex as 0 and it worked.

    Here, dataSetIndex is set to 0 because it is CombinedChartView where i have merged 2 data set.