Skip to content

Commit

Permalink
Use Double instead of Float (rel #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Jan 7, 2018
1 parent f6456a9 commit 67c5276
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Example/SwiftChart/BasicChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import UIKit
import SwiftChart

class BasicChartViewController: UIViewController, ChartDelegate {


@IBOutlet weak var chart: Chart!
var selectedChart = 0

Expand Down Expand Up @@ -51,7 +53,7 @@ class BasicChartViewController: UIViewController, ChartDelegate {
// Chart with y-min, y-max and y-labels formatter


let data: [Float] = [0, -2, -2, 3, -3, 4, 1, 0, -1]
let data: [Double] = [0, -2, -2, 3, -3, 4, 1, 0, -1]

let series = ChartSeries(data)
series.area = true
Expand All @@ -78,7 +80,7 @@ class BasicChartViewController: UIViewController, ChartDelegate {

// Chart delegate

func didTouchChart(_ chart: Chart, indexes: Array<Int?>, x: Float, left: CGFloat) {
func didTouchChart(_ chart: Chart, indexes: Array<Int?>, x: Double, left: CGFloat) {
for (seriesIndex, dataIndex) in indexes.enumerated() {
if let value = chart.valueForSeries(seriesIndex, atIndex: dataIndex) {
print("Touched series: \(seriesIndex): data index: \(dataIndex!); series value: \(value); x-axis value: \(x) (from left: \(left))")
Expand Down
14 changes: 7 additions & 7 deletions Example/SwiftChart/StockChartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class StockChartViewController: UIViewController, ChartDelegate {
// Initialize data series and labels
let stockValues = getStockValues()

var serieData: [Float] = []
var labels: [Float] = []
var serieData: [Double] = []
var labels: [Double] = []
var labelsAsString: Array<String> = []

// Date formatter to retrieve the month names
Expand All @@ -42,13 +42,13 @@ class StockChartViewController: UIViewController, ChartDelegate {

for (i, value) in stockValues.enumerated() {

serieData.append(value["close"] as! Float)
serieData.append(value["close"] as! Double)

// Use only one label for each month
let month = Int(dateFormatter.string(from: value["date"] as! Date))!
let monthAsString:String = dateFormatter.monthSymbols[month - 1]
if (labels.count == 0 || labelsAsString.last != monthAsString) {
labels.append(Float(i))
labels.append(Double(i))
labelsAsString.append(monthAsString)
}
}
Expand All @@ -61,7 +61,7 @@ class StockChartViewController: UIViewController, ChartDelegate {
chart.lineWidth = 0.5
chart.labelFont = UIFont.systemFont(ofSize: 12)
chart.xLabels = labels
chart.xLabelsFormatter = { (labelIndex: Int, labelValue: Float) -> String in
chart.xLabelsFormatter = { (labelIndex: Int, labelValue: Double) -> String in
return labelsAsString[labelIndex]
}
chart.xLabelsTextAlignment = .center
Expand All @@ -74,7 +74,7 @@ class StockChartViewController: UIViewController, ChartDelegate {
}
// Chart delegate

func didTouchChart(_ chart: Chart, indexes: Array<Int?>, x: Float, left: CGFloat) {
func didTouchChart(_ chart: Chart, indexes: Array<Int?>, x: Double, left: CGFloat) {

if let value = chart.valueForSeries(0, atIndex: indexes[0]) {

Expand Down Expand Up @@ -126,7 +126,7 @@ class StockChartViewController: UIViewController, ChartDelegate {
dateFormatter.dateFormat = "yyyy-MM-dd"
let values = jsonValues.map { (value: NSDictionary) -> Dictionary<String, Any> in
let date = dateFormatter.date(from: value["date"]! as! String)
let close = (value["close"]! as! NSNumber).floatValue
let close = (value["close"]! as! NSNumber).doubleValue
return ["date": date!, "close": close]
}

Expand Down

0 comments on commit 67c5276

Please sign in to comment.