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

bar chart from dates #1963

Closed
abara-kedavra opened this issue Dec 15, 2016 · 2 comments
Closed

bar chart from dates #1963

abara-kedavra opened this issue Dec 15, 2016 · 2 comments

Comments

@abara-kedavra
Copy link

abara-kedavra commented Dec 15, 2016

HI! I try to make a bar chart from numbers and dates. As I know now I can use only "Double" values. But if I convert "Double(date.timeIntervalSince1970)" I get only a point in a day during one second, and my bars are too thin. Is it possible to show dates in Charts like whole day ("d MMM")? This example from Sami Korpela tutorial from your main page. I just use dates from database (day/month/year 21.00).

weak var axisFormatDelegate: IAxisValueFormatter?
////////
let timeIntervalForDate: TimeInterval = objects[i].date!.timeIntervalSince1970
let dataEntry = BarChartDataEntry(x: Double(timeIntervalForDate), y: Double(objects[i].number))
dataEntries.append(dataEntry)   
////////
let xaxis = barView.xAxis
xaxis.valueFormatter = axisFormatDelegate
//////////
extension ViewController: IAxisValueFormatter {
     
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "d MMM"
        return dateFormatter.string(from: Date(timeIntervalSince1970: value))
    }
}
@liuxuan30
Copy link
Member

liuxuan30 commented Dec 19, 2016

I suggest rethink what you need. Yes the x axis only take double for now, but you can definitely use int to format or some small values.. currently the formatter will have issue if you zoom in.
#1956

@StevenPeeters
Copy link

@liuxuan30, So it is not possible to create a Bar chart with strings on the x axis and numbers on the y axis? I'm trying to create something like that in OSx with swift 3

@jjatie jjatie closed this as completed Apr 1, 2018
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