XYMarkerView.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // XYMarkerView.swift
  3. // ChartsDemo-iOS
  4. //
  5. // Created by Jacob Christie on 2017-07-09.
  6. // Copyright © 2017 jc. All rights reserved.
  7. //
  8. import Foundation
  9. import Charts
  10. #if canImport(UIKit)
  11. import UIKit
  12. #endif
  13. public class XYMarkerView: BalloonMarker {
  14. public var xAxisValueFormatter: AxisValueFormatter
  15. fileprivate var yFormatter = NumberFormatter()
  16. public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets,
  17. xAxisValueFormatter: AxisValueFormatter) {
  18. self.xAxisValueFormatter = xAxisValueFormatter
  19. yFormatter.minimumFractionDigits = 1
  20. yFormatter.maximumFractionDigits = 1
  21. super.init(color: color, font: font, textColor: textColor, insets: insets)
  22. }
  23. public override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
  24. let string = "x: "
  25. + xAxisValueFormatter.stringForValue(entry.x, axis: XAxis())
  26. + ", y: "
  27. + yFormatter.string(from: NSNumber(floatLiteral: entry.y))!
  28. setLabel(string)
  29. }
  30. }