Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candlestick Chart Issue with Version 4.0.2 (Pod was updated from 3.6.0) #4792

Closed
Spencer-Villarreal opened this issue Mar 13, 2022 · 4 comments

Comments

@Spencer-Villarreal
Copy link

I run 'pod update' about every single day just to make sure I am up-to-date on the latest releases. Today the Charts pod got updated from version 3.6.0 to 4.0.2 and now my candlestick chart is unusable.

When I was using the 3.6.0 version I followed the swift demo to get everything set up, but once I updated to 4.0.2 the whole chart does not show data correctly anymore. As of right now, only one candlestick is showing on the far left side and no other candles are shown on the screen. I cannot tell if all of the candles are being rendered on the far left side or if only one candle is being shown.

There are 19 chart values but only 1 value is being shown on the far left side. I set the x-axis to be the same amount of chart values + 2 for some spacing.

I have downgraded back to 3.6.0 and it goes back to normal/works completely fine. Does anyone know what could possibly be happening from the update?

If it is possible could you create a new candlestick chart demo for the new 4.0.0 update?

@dborelli
Copy link

dborelli commented Mar 15, 2022

I have the same situation with a multiple-set line chart. Debugging shows multiple datasets in the LineChartData object, but only the first will be displayed. There was some sort of breaking change that's not apparent to me in the 4.x update. The demo version of the multiple line charts still works correctly, but it's the same example code I used in my original implementation.

@dborelli
Copy link

@Spencer-Villarreal, use the fix that's in this PR: #4687

I realized that I'd manually fixed this back in the 3.x days and pulling the new 4.0.2 on a new machine doesn't my manual change.

@ghost
Copy link

ghost commented Mar 19, 2022

Same issue. When will we see a fix for this?

@blazarz
Copy link

blazarz commented May 19, 2022

Here's the issue and (not thoroughly tested) fix. Sorry, I'm not a Swift guy, so I'm not comfortable pulling/posting this fix...

The drawDataset method in CandleStickRenderer.swift sets the min, max and range values for _xBounds

_xBounds.set(chart: dataProvider, dataSet: dataSet, animator: animator)

The XBounds setter is found in BarLineScatterCandleBubbleRenderer.swift. The entryTo value is what's not getting set correctly.

let entryTo = dataSet.entryForXValue(high, closestToY: .nan, rounding: .up)

This method calls the entryIndex method in ChartDataSet.swift that tries to find the closest X value.

open override func entryForXValue(
        _ xValue: Double,
        closestToY yValue: Double,
        rounding: ChartDataSetRounding) -> ChartDataEntry?
    {
        let index = entryIndex(x: xValue, closestToY: yValue, rounding: rounding)
        if index > -1
        {
            return self[index]
        }
        return nil
    }

The problem is that it's greater than the number of dataset elements, so it returns -1.
I changed the logic to use the last element when the closest value is beyond the number of elements.
//The fix:

open override func entryIndex(
    x xValue: Double,
    closestToY yValue: Double,
    rounding: ChartDataSetRounding) -> Int
{
   var closest = partitioningIndex { $0.x >= xValue }
   //fix begin
   if closest >= endIndex
   {
     closest = endIndex-1
   }
   //fix end
   guard closest < endIndex else { return -1 }
...
...

Again, sorry for my lack of Swift experience. I'm sure there's a more elegant solution to this. I think I'm the last Objective-C holdout...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants