在折线图上查找数据(SwiftCharts)

时间:2018-12-08 13:44:09

标签: swift swift4 linechart swiftcharts

我使用SwiftCharts创建了折线图。现在,我试图在图表上查找数据。用户将输入与x y轴相交的数字,并且迅速标出这两个数字的交点,并告诉用户其折线图上的数据在哪里。如果是,是在这些行的上方,还是在弹出的上方或下方,在该行的上方和下方。 谢谢...

@IBAction func displayChart(_ sender: Any) {
        let chartConfig = ChartConfigXY(
            xAxisConfig: ChartAxisConfig(from: 0, to:192 , by: 24),
            yAxisConfig: ChartAxisConfig(from: 0, to: 22, by: 1)
        )
        let frame = CGRect(x: 10, y: 100, width: self.view.frame.width-50, height: 550)

        let chart = LineChart(frame: frame, chartConfig: chartConfig, xTitle: "Postnatal Age Hours", yTitle: "Total Bilirubin mg/dl" ,
                              lines: [
                                (chartPoints:[(0, 4.0), (12, 6.0), (24, 8.0), (36, 9.5), (48, 11.0), (60, 12.5), (72, 13.5), (84, 14.0), (96, 14.5), (108, 14.9), (120, 15.0), (132, 15.0), (144, 15.0), (156, 15.0),  (168, 15.0)], color: UIColor.red),
                                (chartPoints:[(0, 5.0), (12, 7.5), (24, 10.0), (36, 11.8), (48, 13.0), (60, 14.5), (72, 15.1), (84, 16.4), (96, 17.1), (108, 18.0), (120, 18.0), (120, 18.0), (132, 18.0), (144, 18.0), (156, 18.0), (168, 18.0)], color : UIColor.blue),
                                (chartPoints:[(0, 6.5), (12, 9.0), (24, 11.5), (36, 13.5), (48, 15.0), (60, 16.5), (72, 17.5), (84, 19.0), (96, 20.0), (108, 20.5), (120, 21.0), (132, 21.0), (144, 21.0), (156, 21.0), (168, 21.0)], color: UIColor.green)

            ])

        self.view.addSubview(chart.view)
        self.pttChartView = chart
    }

0 个答案:

没有答案