How to create a line chart with multiple data series and each line having a different gradient background in Android using Kotlin?

I am working on an Android project using Kotlin where I need to create a line chart with multiple data series. Each series should have its own gradient background, similar to the chart shown in the attached image.Applying different gradient backgrounds under each line.

I am using the MPAndroidChart library and I have managed to plot the lines, but I encounter an issue when applying gradient backgrounds. But the background color of the entire graph is the background color of the highest data series
Out put

val colorArray = arrayOf(ContextCompat.getColor(requireContext(), R.color.medium_blue), ContextCompat.getColor(requireContext(), R.color.light_green),ContextCompat.getColor(requireContext(), R.color.colorSecondary) )
        mpLineChart = view.findViewById(R.id.compositionGraph)
        binding.tvYAxis.rotation = -90f

        with(mpLineChart){

            xAxis.apply {
                setDrawAxisLine(false)
                setDrawGridLines(false)
                position = XAxis.XAxisPosition.BOTTOM
                //setLabelCount(12, true)
                valueFormatter = IndexAxisValueFormatter(monthList)
                //labelRotationAngle = -59F
                granularity = 1f
            }

            axisLeft.apply {
                setDrawAxisLine(false)
                setDrawGridLines(true)
                isEnabled = true
                axisMinimum = 0F
                axisMaximum = 100F
                setLabelCount(11)
            }

            axisRight.apply {
                setDrawAxisLine(false)
                isEnabled = false
            }

            legend.yOffset = 60f
            legend.isEnabled = true

            legend.textSize = 12f
            legend.form = Legend.LegendForm.LINE
            legend.formSize = 12f
            legend.yEntrySpace = 8f
            legend.formToTextSpace = 6f

            val legendEntries = arrayOfNulls<LegendEntry>(3)
            for(i in legendEntries.indices){
                val entry = LegendEntry()
                entry.formColor = colorArray[i]
                entry.label = legendName[i]
                legendEntries[i] = entry
            }

            legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
            legend.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
            legend.orientation = Legend.LegendOrientation.HORIZONTAL
            legend.setDrawInside(false)
            legend.setCustom(legendEntries)
            description.isEnabled = false

        }

        val lineDataSet1 =  LineDataSet(dataValues1(), "Data Values 1")
        lineDataSet1.apply {
            setDrawValues(false)
            lineWidth = 2f
            fillColor = Color.WHITE
            setDrawFilled(true)
            color = ContextCompat.getColor(requireContext(), R.color.medium_blue)
            circleHoleColor = ContextCompat.getColor(requireContext(), R.color.white)
            setCircleColor(requireContext().getColor(R.color.medium_blue))
            circleSize = 5f
            val lineGradient1 = ContextCompat.getDrawable(requireContext(), R.drawable.fade_blue)
            fillDrawable = lineGradient1
        }

        val lineDataSet2 =  LineDataSet(dataValues2(), null)
        lineDataSet2.apply {
            lineWidth = 2f
            setDrawValues(false)
            setDrawFilled(true)
            color = ContextCompat.getColor(requireContext(), R.color.light_green)
            circleHoleColor = ContextCompat.getColor(requireContext(), R.color.white)
            setCircleColor(requireContext().getColor(R.color.light_green))
            circleSize = 5f
            val lineGradient2 = ContextCompat.getDrawable(requireContext(), R.drawable.fade_green)
            fillDrawable = lineGradient2

        }

        val lineDataSet3 =  LineDataSet(dataValues3(), null)
        lineDataSet3.apply {
            lineWidth = 2f
            setDrawValues(false)
            setDrawFilled(true)
            color = ContextCompat.getColor(requireContext(), R.color.colorSecondary)
            circleHoleColor = ContextCompat.getColor(requireContext(), R.color.white)
            setCircleColor(requireContext().getColor(R.color.colorSecondary))
            circleSize = 5f
            val lineGradient3 = ContextCompat.getDrawable(requireContext(), R.drawable.fade_red)
            fillDrawable = lineGradient3
        }

        val dataSets: ArrayList<ILineDataSet> = arrayListOf()
        dataSets.add(lineDataSet1)
        dataSets.add(lineDataSet2)
        dataSets.add(lineDataSet3)

        val data = LineData(dataSets)
        mpLineChart.data = data
        mpLineChart.setVisibleXRangeMaximum(5f)

        val markerView = CustomMarker(requireContext(), R.layout.marker_view_layout)
        mpLineChart.marker = markerView

New contributor

Sukdeb Midya 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