ivnsch / SwiftCharts

Easy to use and highly customizable charts library for iOS
Apache License 2.0
2.53k stars 410 forks source link

Axis Label not getting Displayed iPhone 5s #343

Open iOSDevGarg opened 6 years ago

iOSDevGarg commented 6 years ago

Had Implemented swift Charts in my Project Just facing issue Specifically in iPhone 5s

Chart Values realChartPoints:[(0.0, 0.55803571428571563), (1.0, 0.55803571428571563)] /// That make line to draw chartDateArray:["05/04", "05/04"] // Date Array - Which are not getting displayed I am passing ChartAxisDouble yAxiis as

yValues.append(ChartAxisValueDouble(val2, labelSettings: customChartSettings.labelSetting))

LabelSetting

struct customChartSettings
    {
    static var labelSetting = ChartLabelSettings(font: ExamplesDefaults.labelFont)
    static var labelSettings1 = ChartLabelSettings(font: ExamplesDefaults.fontWithSize(Env.iPad ? 14 : 16))
    }

val2 is The value from a Double Array Array:[3.180625, 4.180625, 5.180625, 6.180625, 7.180625, 8.1806249999999991, 9.1806249999999991]

Issue is my Axis get values displayed in every iPhone series just not in iPhone 5s/5

ScreenShot iPhone x screen shot 2018-04-05 at 3 49 52 pm

Screenshot iPhone 5s screen shot 2018-04-05 at 3 50 03 pm

I Cant understand where is the issue, can you please Suggest what can be the possible issue ? Sometimes the axis display all values sometimes it do not (iPhone 5s)

Re-Update - To Reproduce Issue

  var yValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 5, maxSegmentCount: 5, multiple: 0.01, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: customChartSettings.labelSetting)}, addPaddingSegmentIfEdge: false)

instead of:

   var yValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 5, maxSegmentCount: 5, multiple: 0.1, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: customChartSettings.labelSetting)}, addPaddingSegmentIfEdge: false)

-------------------------Re-Update

I have used a Function Which actually divide a Array Range into some equal Parts

   class func EqualNArrayParts1(Array: [Double]) -> [Double]
{
    var ArrayToReturn = [Double]()
    let x = Array.max()! - Array.min()! //Difference
    if x != 0.0
    {
        let v1 = Double(round(100*(Array.min()! + (x/6.0)))/100)
        let v2 = Double(round(100*(v1 + (x/6.0)))/100)
        let v3 = Double(round(100*(v2 + (x/6.0)))/100)
        let v4 = Double(round(100*(v3 + (x/6.0)))/100)

        ArrayToReturn.append(Array.min()!-(x/6))
        ArrayToReturn.append(Double(v4))
        ArrayToReturn.append(Double(v3))
        ArrayToReturn.append(Double(v2))
        ArrayToReturn.append(Double(v1))
        ArrayToReturn.append(Array.max()!)
        ArrayToReturn.append(Array.max()!+(x/6))
        return ArrayToReturn
    }
    else
    {
        ArrayToReturn.append(Array.min()! - 3)
        ArrayToReturn.append(Array.min()! - 2)
        ArrayToReturn.append(Array.min()! - 1)
        ArrayToReturn.append(Array.min()!)
        ArrayToReturn.append(Array.min()! + 1)
        ArrayToReturn.append(Array.min()! + 2)
        ArrayToReturn.append(Array.min()! + 3)
        return ArrayToReturn
    }        
}

Above function I use to get a new Array with equal Values and its output can also vary from -Values to +values

Axis Values

   var xValues = chartPoints.map{$0.x}
    var yValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 5, maxSegmentCount: 5, multiple: 0.1, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: customChartSettings.labelSetting)}, addPaddingSegmentIfEdge: false)

x Values are my dates That I show below The chart

I modify my Y-Values with the values that I am getting from my class function as

     yValues.removeAll()
        if self.addHigherValueExplictly(array: afiValuesArray){
            afiValuesArray.append(1.01)
        }
        //Array With Equal Parts
        var aa : [Double] = WrapperClass.EqualNArrayParts1(Array: afiValuesArray.sorted(by: <))
        aa = aa.sorted(by: <)
        chartLeadcaseIs = WrapperClass.getLeadCase(MA: aa)
        for i in 0..<aa.count
        {
            let val2 = aa[i].rounded(toPlaces: 2)
            iPhone5sArray.append(ChartAxisValueDouble(val2, labelSettings: customChartSettings.labelSetting))
            yValues.append(ChartAxisValueDouble(val2, labelSettings: customChartSettings.labelSetting))
        }
        aa.removeAll()

Now Models

   let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "", settings: customChartSettings.labelSetting))
    let yModel = ChartAxisModel(axisValues: iPhone5sArray, axisTitleLabel: ChartAxisLabel(text: "AFI", settings: axisLabelSetting.defaultVertical()))

and output as I shared iPhone 5s Issue , Rest devices works Perfectly

and I also found one thing in your awesome library

if I provide multplier as in range of 0.01 to 0.09 the same issue will occur as in Screenshots multiplier is here

 var yValues = ChartAxisValuesStaticGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 5, maxSegmentCount: 5, multiple: 0.1, axisValueGenerator: {ChartAxisValueDouble($0, labelSettings: customChartSettings.labelSetting)}, addPaddingSegmentIfEdge: false)
iOSDevGarg commented 6 years ago

@i-schuetz Please Help

ivnsch commented 6 years ago

Please compare on the iPhone 5 with the examples - to find what's different in your chart, which causes this issue - and read the wiki https://github.com/i-schuetz/SwiftCharts/wiki/Axes - you can use dynamic label generators instead ChartAxisValuesStaticGenerator. This exists mostly only for backwards compatibility. Let me know if this helps.

iOSDevGarg commented 6 years ago

I check using as you mentioned issues is same I will Reupdate my question and will let you know When I actually face the issue

iOSDevGarg commented 6 years ago

@i-schuetz Please check I have shared my Brief code with you with steps