MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

How to access individual bar items in a bar graph - Helpful from accessibility point of view too

Open Hiten1984 opened this issue 2 years ago • 0 comments

Hi there,

I am using MPAndroidChart Library to show bar items.

Currently when I am trying to get focus on each individual item in the bar graph, I am not able to do so, rather getting the focus on the whole chart. I am trying to access the individual items or the child views inside the bar graph and trying to get focus on each item so that accessibility can work on items separately.

When I am trying to look in the layout inspector as well, not seeing the focus going in the individual items and there are no view identifiers too for each item. Just for the whole graph.

This is how I have implemented in the code

This is the xml

<com.github.mikephil.charting.charts.BarChart android:id="@+id/chart" android:importantForAccessibility="yes" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="48dp"/>

Also in the Kotlin file,

private fun init() { binding = ViewBinding.inflate(LayoutInflater.from(context), this, true)

    with(binding.chart) {
        // Disable all the default cruft
        setDrawBorders(false)
        setPinchZoom(false)
        
// THIS IS HOW I AM ACHIEVING THE ACCESSIBILITY READING FOR THE WHOLE GRAPH
        contentDescription = "This is a bar chart accessibility testing example."

        isHighlightPerDragEnabled = false
        isDoubleTapToZoomEnabled = false
        legend.isEnabled = false

        // Precisely fit the bars to the screen
        setFitBars(true)
    }

}

Has someone been able to achieve this?

I tried getting the view Identifier for each item but was not able to do so. Tried to check in the library to somehow request focus at child elements but was not able to do so.

So trying to figure out how can I achieve.

Any reply or support on the above will be highly appreciated.

Hiten1984 avatar Aug 21 '23 04:08 Hiten1984