Reputation: 1127
I have a graph and when I touch it. It successfully highlights our graph, but I cannot seem to retrieve the specific datapoint that is being selected.
To be even more specific I am using a horizontal bar graph such that it is a segmented bar graph. This is our datatype used to create the bar graph is:
updateGraph(list: Array<Double>) {
let dataEntries = [BarChartDataEntry(x: 0.0, yValues: list)]
let barChartDataSet = BarChartDataSet(values: dataEntries, label: "")
let colorValues = colorList.map( { $0.color })
barChartDataSet.colors = colorValues//ChartColorTemplates.material()
let labelValues = nameList.map( { $0.name })
barChartDataSet.stackLabels = labelValues
let barChartData = BarChartData(dataSet: barChartDataSet)
barChartData.setValueFont(UIFont.systemFont(ofSize: 12.0))
barChart.data = barChartData
}
Now when I select a specific part of this graph, I can successfully get chartValueSelected to fire, however it returns no useful data that can identify the specific list index being selected.
Upvotes: 1
Views: 1500
Reputation: 1127
After an h our or so of reading the API docs and messing around with things it appears that the function chartValueSelected
gives access to a chart highlight
which you can extract the data index path out of using highlight.stackIndex
.
very frustrating variable naming by charts... stackIndex
is very counter intuitive, but alas solved.
Upvotes: 1
Reputation: 6635
I'm not familiar with this library, but from reading the source, it seems like the ChartViewDelegate.chartValueSelected
method should have a parameter dataEntry: DataEntry
which should refer to the selected entry. Is your chartValueSelected
method being called? Can you update your question with its contents?
Upvotes: 0