用lineChart画一个圆

问题描述 投票:1回答:1

[我正在尝试使用Charts使用LineChartView绘制一个圆,我用抛物线做这个没问题,但是当我尝试一个圆时,我得到了

Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem.

If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable.

奇怪的是,如果我缩放并向右移动图形,我会看到圆圈的一部分看起来像这样this

在我得到的viewDidLoad()上

chartView.delegate = self

    chartView.chartDescription?.enabled = false

    chartView.dragEnabled = true
    chartView.setScaleEnabled(true)
    chartView.pinchZoomEnabled = true
    chartView.highlightPerDragEnabled = true

    chartView.backgroundColor = .white

    chartView.legend.enabled = false


    let xAxis = chartView.xAxis
    xAxis.labelFont = .systemFont(ofSize: 10, weight: .light)
    xAxis.labelTextColor = UIColor.black
    xAxis.drawAxisLineEnabled = true
    xAxis.drawGridLinesEnabled = true
    xAxis.gridLineWidth = 1
    xAxis.gridLineDashLengths = [1,1]
    xAxis.axisMaximum = 100
    xAxis.axisMinimum = -100

    xAxis.granularity = 0.5
    let leftAxis = chartView.leftAxis
    leftAxis.labelPosition = .insideChart
    leftAxis.labelFont = .systemFont(ofSize: 12, weight: .light)
    leftAxis.drawGridLinesEnabled = true
    leftAxis.gridLineWidth = 1
    leftAxis.gridLineDashLengths = [1,1]
    leftAxis.granularityEnabled = true
    leftAxis.axisMinimum = -100
    leftAxis.axisMaximum = 100
    leftAxis.granularity = 0.5
    leftAxis.yOffset = -9
    leftAxis.labelTextColor = UIColor.black

    chartView.xAxis.gridLineDashLengths = [1,1]
    chartView.rightAxis.enabled = false

    chartView.legend.form = .line


    setDataCount()
    //chartView.animate(xAxisDuration: 2.5)

这基本上就是我的功能

func setDataCount() {

    let yVal1 = (-100...100).map {

        return ChartDataEntry(x: Double($0), y: sqrt(100 - pow(Double($0), 2)))

    }

    let yVal2 = (-100...100).map {
       return ChartDataEntry(x: Double($0), y: sqrt(100 - pow(Double($0), 2)) * -1)
    }

    let set1 = LineChartDataSet(values: yVal1, label: "Top")
     //set1.axisDependency = .left
     set1.setColor(UIColor.red)
     set1.drawCirclesEnabled = false
     set1.lineWidth = 2
    set1.mode = .cubicBezier

    let set2 = LineChartDataSet(values: yVal2, label: "Bottom")
    set2.setColor(UIColor.black)
    set2.drawCirclesEnabled = false
    set2.lineWidth = 2

    set2.mode = .cubicBezier

    let data = LineChartData(dataSets: [set1,set2])

    data.setValueFont(.systemFont(ofSize: 9))
    data.setDrawValues(false)
    chartView.data = data
}

我仍在学习和尝试图形,所以我真的不知道问题出在哪里,如何在LineChartView中正确显示圆?

swift charts ios-charts
1个回答
0
投票

更改数据集的drawCirclesEnabled属性。

set1.drawCirclesEnabled = trueset2.drawCirclesEnabled = true

© www.soinside.com 2019 - 2024. All rights reserved.