ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.51k stars 5.99k forks source link

How to Fill Area Between Two Lines with Different Colors Based on Line Intersection #5195

Open phucdanghuu opened 3 weeks ago

phucdanghuu commented 3 weeks ago

Hello,

I am trying to create a line chart using DGCharts where I need to fill the area between two lines with different colors based on which line is higher at any given point on the x-axis.

Details: I have two data sets representing two lines on the chart. My goal is to: Fill the area between these two lines.

I’ve tried using a custom FillFormatter and overriding the fill logic, but I’ve encountered difficulties getting the correct areas to fill between the lines. In my current implementation, the fill area doesn’t cover the space correctly, and sometimes it fills the wrong segments.

Question: What would be the best approach to achieve this effect in DGCharts? Are there any examples or best practices to follow for creating such a fill effect?

The screenshot is what I'm trying to do: Simulator Screenshot - iPhone 15 Pro - 2024-08-22 at 10 41 02