使用雨燕采用IOS-排行榜线图没有显示负值(Negative values not displaye

2019-10-22 22:54发布

我使用的是iOS,图表在我的折线图负值。 显示正值,但负值为0夹住我已经设置了左,右轴不为0,但没有帮助启动。

    LineChart1.leftAxis.startAtZeroEnabled = false
    LineChart1.rightAxis.startAtZeroEnabled = false

有任何想法吗? TIA。

代码段下方。

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    self.navigationController?.navigationBar.translucent = false

    self.title = "Line Chart 1"
    LineChart1.bounds = CGRectMake(-20, -20, 275, 250)
    LineChart1.data = getMyData()
    LineChart1.drawBordersEnabled = false
    LineChart1.legend.enabled = false
    LineChart1.leftAxis.startAtZeroEnabled = false
    LineChart1.rightAxis.startAtZeroEnabled = false
    LineChart1.xAxis.setLabelsToSkip(0)
    LineChart1.xAxis.drawGridLinesEnabled = false
    LineChart1.leftAxis.drawGridLinesEnabled = true
    LineChart1.rightAxis.drawLabelsEnabled = false
    LineChart1.animate(xAxisDuration: 0.3)
    LineChart1.animate(yAxisDuration: 0.3)

    LineChart1.setNeedsDisplay()
}

func getMyData() -> LineChartData {

    var xVals = ["2008","2009","2010","2011","2012"]

    var courses: [ChartDataEntry] = []
    courses.append(ChartDataEntry(value: 3, xIndex: 0))
    courses.append(ChartDataEntry(value: -40, xIndex: 1))
    courses.append(ChartDataEntry(value: 4, xIndex: 2))
    courses.append(ChartDataEntry(value: 4, xIndex: 3))
    courses.append(ChartDataEntry(value: 3, xIndex: 4))

    let bcds = LineChartDataSet(yVals: courses, label: "")
    bcds.valueTextColor = UIColor.blackColor()

    return LineChartData(xVals: xVals, dataSet: bcds)
}

Answer 1:

你应该叫notifyDataSetChanged()设置后startAtZeroEnabled像示例应用程序- 。

图表不知道在这样一个性质的变化startAtZeroEnabled一个内部部件上,所以你必须告诉它。 而由于最小值/最大值在计算notifyDataSetChanged根据startAtZeroEnabled ,这就是你必须通知的情况下,只是setNeedsDisplay ...



文章来源: Negative values not displayed in line charts using ios-charts using Swift
标签: ios-charts