Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar chart does not start at zero. #2927

Closed
ltonl opened this issue Oct 30, 2017 · 1 comment
Closed

Bar chart does not start at zero. #2927

ltonl opened this issue Oct 30, 2017 · 1 comment

Comments

@ltonl
Copy link

ltonl commented Oct 30, 2017

anyone can help me?
I try several time to solve the problem
<img width="132" alt="screen shot 2560-10-30 at 21 11 09" src="https://user-
screen shot 2560-10-30 at 21 14 28

this is my code

func setChart(dataPoints: [String], values: [Double]) {
barChartView.delegate = self
barChartView.chartDescription?.enabled = false
barChartView.highlightPerTapEnabled = false
barChartView.drawValueAboveBarEnabled = false
barChartView.fitBars = true
barChartView.drawBarShadowEnabled = false
barChartView.drawGridBackgroundEnabled = false
barChartView.pinchZoomEnabled = false
barChartView.doubleTapToZoomEnabled = false
// barChartView.autoScaleMinMaxEnabled = true
// barChartView.scaleYEnabled = false
// barChartView.scaleXEnabled = false
barChartView.animate(xAxisDuration: 0.5, yAxisDuration: 0.5, easingOption: .easeInBounce)

    let axisMinimum = 0.0
    let axisMaximum = 3.0
    
    let rightAxis = barChartView.rightAxis
    rightAxis.enabled = false
    rightAxis.axisMinimum = axisMinimum
    rightAxis.drawAxisLineEnabled = false
    rightAxis.drawGridLinesEnabled = false
    rightAxis.drawZeroLineEnabled = true
    
    let yAxis = barChartView.leftAxis
    yAxis.enabled = false
    yAxis.axisMinimum = axisMinimum
    yAxis.spaceBottom = 0.0
    yAxis.drawAxisLineEnabled = true
    yAxis.drawGridLinesEnabled = true
    yAxis.drawZeroLineEnabled = true

    let xAxis = barChartView.xAxis
    xAxis.drawLabelsEnabled = true
    xAxis.drawAxisLineEnabled = true
    xAxis.drawGridLinesEnabled = true
    xAxis.labelTextColor = .white
    xAxis.granularity = 1.0
    xAxis.centerAxisLabelsEnabled = true
    xAxis.axisMinimum = axisMinimum
    xAxis.axisMaximum = axisMaximum
    xAxis.labelPosition = .top
    
    let legend = barChartView.legend
    legend.enabled = false
    
    var dataEntries: [BarChartDataEntry] = []
    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: Double(values[i]), data: dataPoints as AnyObject?)
        dataEntries.append(dataEntry)
    }
            
    let chartDataSet = BarChartDataSet(values: dataEntries, label: nil)
    let chartData = BarChartData(dataSet: chartDataSet)
    chartData.setValueTextColor(NSUIColor.clear)
    barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)
    barChartView.drawBordersEnabled = false
    barChartView.data = chartData

    var colors: [UIColor] = []
    colors = [zeroColor, firstColor, secondColor]
    chartDataSet.colors = colors
    chartData.barWidth = 1
}

thank for your help

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 6, 2017

try yAxis.axisMinimum = 0 and if not work, post an image with y axis label enabled so we see where is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants