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

Line Chart View not drawn because Date values in xAxis (not sorted Ascending/Descending) ? #2988

Closed
Mohammed-Elias opened this issue Nov 13, 2017 · 4 comments

Comments

@Mohammed-Elias
Copy link

I'm using version 3.0.2 for swift 3
I have this format for the date from the api as String : "2017-11-04 16:48:55"

   ["2017-11-09 14:22:54","2017-11-09 14:22:07","2017-11-09 14:21:20","2017-11-04 18:58:01","2017-11-04 16:48:55","2017-11-04 16:35:00"]

So I convert the string to date through formatter

        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        dateFormatter.timeZone = TimeZone(abbreviation: "GMT+0:00")

        let date = dateFormatter.date(from: updatedAt)
        let timeInerval = date?.timeIntervalSince1970
        let hour = Int(timeInerval!)
        dates.append(Double(hour))

if I printed the dates array I'll get :

  [1510237374.0, 1510237327.0, 1510237280.0, 1509821881.0, 1509814135.0, 1509813300.0]

        let dateFormatterForXAxis = DateValueFormatter()
        chartView.xAxis.valueFormatter = dateFormatterForXAxis

where DateValueFormatter class :

        import Foundation
        import Charts

        class DateValueFormatter: NSObject, IAxisValueFormatter {

            var dateFormatter: DateFormatter!

            override init() {
                dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "h"
            }

            func stringForValue(_ value: Double, axis: AxisBase?) -> String {
                return dateFormatter.string(from: Date(timeIntervalSince1970: value))
            }
        }

The chartView haven't drawn, because the values not sorted Ascending/Descending
Any ideas how to solve this issue ?

@Mohammed-Elias Mohammed-Elias changed the title Date values not drawn in xAxis (because not sorted Ascending/Descending) ? Line Chart View not drawn because Date values in xAxis (not sorted Ascending/Descending) ? Nov 13, 2017
@liuxuan30
Copy link
Member

liuxuan30 commented Nov 15, 2017

seems you have to make it ordered? I suspect it's because XBounds needs

@Mohammed-Elias
Copy link
Author

Mohammed-Elias commented Nov 15, 2017

@liuxuan30 when I use something like xAxisValues = [12,23,44,10,11,22] the chat didn't draw, because the values not sorted ascending.
when I use ascending sorted array the chart drawn with no sweat, otherwise don't.

What should I do with XBounds, could you please explain more ?

@liuxuan30
Copy link
Member

need to take a look at Xbounds how it calculates form your x values. But I guess we don't support this. imaging a line that will turn back, kind of wierd?

@Mohammed-Elias
Copy link
Author

Thanks for your time man, But I solved it 2 days ago with ChartDataEntry(x: ,y: ,data:) where I generate the values of x through for loop then send the date in data parameter.
and inside the balloon marker I show the date and the price.

Feel free to close this issue ! :)

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

2 participants