条形图给出负值

时间:2017-06-29 05:49:30

标签: ios charts swift3 xscale

我正在使用Charts API并实现图表。我是新手,并没有适合Swift 3的文档。

我尝试并实施但不知道如何删除y的负面比例。如何从0开始绘制图形,因此它不显示负y尺度?

以下是我的代码:

fileprivate func ChartViewProperty() {

    barChartView.xAxis.labelPosition = .bottom
    barChartView.chartDescription?.text = ""
    barChartView.fitBars = true
    barChartView.pinchZoomEnabled = false
    self.barChartView.rightAxis.enabled = false
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)

    barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
    barChartView.xAxis.granularity = 1
    value.append([jan,feb,mar,apr,may,jun,jly,aug,sep,oct,nov,dec])
    setChart(dataPoints: months, values: value)
}. 

图像:

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:0)

尝试设置axisMinValue属性

我猜barChartView.xAxis.axisMinValue

答案 1 :(得分:0)

fileprivate func ChartViewProperty() {

    //barChartView.xAxis.drawGridLinesEnabled = false
    barChartView.xAxis.drawAxisLineEnabled = false

    //barChartView
    barChartView.xAxis.drawLabelsEnabled = true

    //Space between x axis
    barChartView.xAxis.spaceMin  = 1.0
    barChartView.xAxis.spaceMax  = 1.0

    //Left axis bottom
    barChartView.leftAxis.spaceBottom = 0.0

    //Label Position
    barChartView.xAxis.labelPosition = .bottom

    //Description
    barChartView.chartDescription?.text = ""

    //Fit Bar
    barChartView.fitBars = false

    //Pinch Zoom
    barChartView.pinchZoomEnabled = false

    //Right x axis enabled
    self.barChartView.rightAxis.enabled = false

    //Animate barchart
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)
}

答案 2 :(得分:0)

此行从条形图中删除所有负值:

chartView.rightAxis.axisMinimum = 0