Я надеюсь, что эта библиотека поможет вам
https://github.com/danielgindi/Charts
import Charts
@IBOutlet weak var chartView: LineChartView!
var options: [Option]!
let dayOfWeeks = ["mon", "tue", "wen", "thu", "fri", "sat", "sun"]
func settingsChart() -> Void {
self.options = [.toggleValues,
.toggleFilled,
.toggleCircles,
.toggleCubic,
.toggleHorizontalCubic,
.toggleIcons,
.toggleStepped,
.toggleHighlight,
.animateX,
.animateY,
.animateXY,
.saveToGallery,
.togglePinchZoom,
.toggleAutoScaleMinMax,
.toggleData]
chartView.chartDescription?.enabled = false
chartView.dragEnabled = true
chartView.setScaleEnabled(true)
chartView.pinchZoomEnabled = true
chartView.legend.form = .line
chartView.rightAxis.enabled = false
let xAxis = chartView.xAxis
xAxis.labelPosition = .bottom
xAxis.granularity = 1
xAxis.gridLineDashLengths = [10, 10]
xAxis.gridLineDashPhase = 0
xAxis.valueFormatter = self
}
func showDataOnChartView() -> Void {
let data = [5000.0, 5100.0, 5200.0] // In your case, this array must have only 3 elements!
let values = (0..<data.count).map { (i) -> ChartDataEntry in
let val:Double = data[i]
return ChartDataEntry(x: Double(i), y: val, icon: UIImage(named: "ic_test"))
}
let set1 = LineChartDataSet(values: values, label: "Test")
set1.drawIconsEnabled = false
set1.lineDashLengths = [5, 0.5]
set1.highlightLineDashLengths = [5, 2.5]
set1.setColor(Utility.mainBlueColor)
set1.setCircleColor(Utility.mainBlueColor)
set1.lineWidth = 1
set1.circleRadius = 3
set1.drawCircleHoleEnabled = false
set1.valueFont = .systemFont(ofSize: 9)
set1.formLineDashLengths = [5, 2.5]
set1.formLineWidth = 1
set1.formSize = 15
let gradientColors = [ChartColorTemplates.colorFromString("#00ff0000").cgColor,
ChartColorTemplates.colorFromString("#ffff0000").cgColor]
let gradient = CGGradient(colorsSpace: nil, colors: gradientColors as CFArray, locations: nil)!
set1.fillAlpha = 1
set1.fill = Fill(linearGradient: gradient, angle: 90) //.linearGradient(gradient, angle: 90)
set1.drawFilledEnabled = true
let chartData = LineChartData(dataSets: [set1])
chartView.data = chartData
for set in chartView.data!.dataSets as! [LineChartDataSet] {
set.drawValuesEnabled = false
}
chartView.animate(yAxisDuration: 2.5)
}
И источник данных:
extension TotalSalesVC: IAxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
if value != -1 && !value.isNaN{
return NSLocalizedString(dayOfWeeks[Int(value) % dayOfWeeks.count] , comment: "")
}
return ""
}
}