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

xAxis value starting at "-1" instead of "0" in grouped barchart #1739

Closed
GLianwei opened this issue Oct 28, 2016 · 1 comment
Closed

xAxis value starting at "-1" instead of "0" in grouped barchart #1739

GLianwei opened this issue Oct 28, 2016 · 1 comment

Comments

@GLianwei
Copy link

GLianwei commented Oct 28, 2016

Here is my code:

    for i in 0..<recordsCount {
        let aEntry = BarChartDataEntry(x: Double(i), y: Double(self.yvalsA[i]))
        let bEntry = BarChartDataEntry(x: Double(i), y: Double(self.yvalsB[i]))
        aEntries.append(aEntry)
        bEntries.append(bEntry)
    }

    let setA = BarChartDataSet(values: aEntries, label: "a values")
    let setB = BarChartDataSet(values: bEntries, label: "b values")
    let dataSets = [setA, setB]
    let data = BarChartData(dataSets: dataSets)
    data.barWidth = 0.3
    data.groupBars(fromX: 0, groupSpace: 0.2, barSpace: 0.1)
    self.barChartView?.data = data
    self.barChartView?.xAxis.labelPosition = XAxis.LabelPosition.bottom
    self.barChartView?.xAxis.avoidFirstLastClippingEnabled = true
    self.barChartView?.xAxis.drawLabelsEnabled = true
    self.barChartView?.xAxis.labelFont = (self.barChartView?.xAxis.labelFont)!.withSize(self.fontChart)
    self.barChartView?.leftAxis.labelFont = (self.barChartView?.leftAxis.labelFont)!.withSize(self.fontChart)
    self.barChartView?.xAxis.labelCount = self.xAxisMonthInfo.count
    self.barChartView?.xAxis.centerAxisLabelsEnabled = true
    self.barChartView?.animate(xAxisDuration: 1.5, yAxisDuration: 1.5)

Please how I make it started at "0"?

@liuxuan30
Copy link
Member

need more info.. btw, do check ChartsDemo with such things. You should find answer there.
If you see -1, then maybe try set axisMinium to 0. But usually it should be 0. It calculates x axis label values in open func computeAxisValues(min: Double, max: Double), you can check why it calculates -1

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