Issue with non-filling bars in a chart: why are the colors not displaying correctly?

i am facing an issue with a bar chart where the bars are not filling with the assigned colors properly. Instead, they appear as empty. I have tried various methods to set custom colors for the bars, but none seem to work as expected.

private fun showEnergy() {
val list = listOf(
        Triple("23-5-2024", 2010, 4.91),
        Triple("22-5-2024", 960, 13.62),
        Triple("21-5-2024", 5642, 2.0),
        Triple("20-5-2024", 1464, 4.85)
    )
        constraintLayoutStatisticsData.removeAllViews()
        constraintLayoutStatisticsData.addView(energyLayout)
        barChart = constraintLayoutStatisticsData.findViewById(R.id.barChart)
        val maxValue=10000f
        setupBarChart(maxValue)
        val currentDate = Date()
        // Create a list of dates for the last 30 days
        val dates = ArrayList<Date>()
        val calendar = Calendar.getInstance()
        for (i in 0 until 6) {
            calendar.time = currentDate
            calendar.add(Calendar.DAY_OF_MONTH, -i)
            dates.add(calendar.time)
        }
        dates.reverse()
        // Create a list of values, adding 0 for missing dates
        val firstBarEntries = ArrayList<BarEntry>()
        val secondBarEntries = ArrayList<BarEntry>()
        val barWidth = 0.26f
        val groupSpace = 0.32f
        val barSpace = 0.08f
        val dateFormat = SimpleDateFormat("d.M.yy", Locale.getDefault())
        for (date in dates) {
            val formattedDate = dateFormat.format(date)
            val value = list.find { it.first == formattedDate }?.second ?: 0
            firstBarEntries.add(BarEntry(date.time.toFloat()- barWidth / 2, value.toFloat()))
            val value2 = 4000f
            firstBarEntries.add(BarEntry(date.time.toFloat()- barWidth / 2, value2.toFloat()))
        }

        val firstDataSet = BarDataSet(firstBarEntries, "")
        firstDataSet.color=ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.grey)

        val secondDataSet = BarDataSet(secondBarEntries, "")

        val customColors = mutableListOf<Int>()
        for (i in list.indices) {
            val ratio = list[i].second / 4000f
            val color = when {
                ratio >= 0.85 && ratio <= 1.15 -> ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.green)
                ratio < 0.85 -> ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.orange)
                else -> ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.red)
            }
            customColors.add(color)
        }
        firstDataSet.setDrawValues(false)
        secondDataSet.setDrawValues(false)
        secondDataSet.setColors(customColors)
        val dataSet = listOf(firstDataSet, secondDataSet)

        // Create a BarData object and set data sets
        val barData = BarData(dataSet)
        barData.barWidth = barWidth
        val xAxis = barChart.xAxis
        xAxis.axisMinimum = -0.5f
        xAxis.axisMaximum = list.size - 0.5f
        xAxis.valueFormatter = object : ValueFormatter() {
            private val dateFormat = SimpleDateFormat("dd.MM", Locale.getDefault())

            override fun getFormattedValue(value: Float): String {
                val index = value.toInt()
                return if (index >= 0 && index < dates.size) {
                    dateFormat.format(dates[index])
                } else {
                    ""
                }
            }
        }
        barChart.axisLeft.valueFormatter = object : ValueFormatter() {
            override fun getFormattedValue(value: Float): String {
                // Replace commas with spaces
                val formattedValue = value.toInt().toString().replace(',', ' ')

                // Return the formatted value as a string
                return formattedValue
            }
        }
        
        // Set the chart data
        barChart.data = barData

        // Update chart
        barChart.invalidate()

    }

private fun setupBarChart(maxValue: Float) {
        barChart.setDrawBarShadow(false)
        barChart.description.isEnabled = false
        barChart.setMaxVisibleValueCount(60)
        barChart.setPinchZoom(false)
        barChart.setDrawGridBackground(false)
        val xAxis = barChart.xAxis
        xAxis.setDrawGridLines(false)
        xAxis.position = XAxis.XAxisPosition.BOTTOM
        xAxis.textColor = ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.text)
        xAxis.granularity = 1f

        val yAxisLeft = barChart.axisLeft
        yAxisLeft.setDrawAxisLine(false)
        yAxisLeft.textColor = ContextCompat.getColor(constraintLayoutStatisticsData.context, R.color.text)
        val minValue = 0f
        val labelCount = 5
        val interval = Math.ceil((maxValue - minValue) / (labelCount - 1).toDouble()).toFloat()
        yAxisLeft.axisMinimum = minValue
        yAxisLeft.axisMaximum = maxValue
        yAxisLeft.setGranularity(interval)
        yAxisLeft.setLabelCount(labelCount, true)
        yAxisLeft.gridLineWidth = 2f
        barChart.axisRight.isEnabled = false
        barChart.legend.isEnabled = false
    }
 

I have also tried using ARGB values and gradients, but the result remains the same. The bars simply refuse to display the assigned colors.

Has anyone encountered a similar issue with bar charts? What could be causing this problem? Are there any specific configurations or settings that I might be missing?

Any help or suggestions would be greatly appreciated. Thank you in advance!

it needs to be like this:bars with colors
but it is like this:
a

New contributor

Liam Harpe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật