Search code examples
iosobjective-cchartsbar-chartios-charts

How to highlight bar in Bar Chart from custom method using ios charts?


I am using bar chart of ios charts and I am trying to highlight single bar without tap specific bar. If i change value from slider (if slider value move to 50) then a bar which contains the value (50) must be highlight without tap on bar using ios-charts


Solution

  • The iOS-Charts api is identical to the MPAndroidChart android library. So you can refer to MPAndroidChart's docs. From this page, you can see that there are a couple methods available to make a selection programmatically :

    Highlighting programmatically

    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.

    getHighlighted(): Returns an Highlight[] array that contains information about all highlighted entries, their x-index and dataset-index.

    so on the sliderValueChanged event you could call something like this :

    [_chartView highlightValueWithXIndex:2 dataSetIndex:0 callDelegate:NO];