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

BarChartView showing consecutive values in xAxis #3843

Closed
jiffy-arti opened this issue Feb 14, 2019 · 2 comments
Closed

BarChartView showing consecutive values in xAxis #3843

jiffy-arti opened this issue Feb 14, 2019 · 2 comments

Comments

@jiffy-arti
Copy link

What did you do?

ℹ I am using a bar chart and line chart to draw few values. I have 12 months in x-axis but when ran it reduces the count to 6 and showing alternate values.

What did you expect to happen?

ℹ I want to show user full 12 values all the time and zoom user from zooming.

Bar Chart Code

    barChartView.noDataText = noDataText
    barChartView.chartDescription?.text = ""
    //legend
    let legend = barChartView.legend
    legend.enabled = true
    legend.horizontalAlignment = .right
    legend.verticalAlignment = .top
    legend.orientation = .vertical
    legend.drawInside = true
    legend.yOffset = 10.0;
    legend.xOffset = 10.0;
    legend.yEntrySpace = 0.0;
    
    // X - Axis Setup
    let xaxis = barChartView.xAxis
    self.months = xAxisData
    xaxis.valueFormatter = IndexAxisValueFormatter(values: xAxisData)
    
    xaxis.labelPosition = .bottom
    xaxis.centerAxisLabelsEnabled = true
    xaxis.granularity = 1
    xaxis.drawGridLinesEnabled = false
    xaxis.enabled = true
    xaxis.drawGridLinesEnabled = false
    xaxis.drawLabelsEnabled = true
    barChartView.rightAxis.enabled = false

    // Y - Axis Setup
    let yaxis = barChartView.leftAxis
    yaxis.spaceTop = 0.35
    yaxis.axisMinimum = 0
    yaxis.drawGridLinesEnabled = false
    
    //Create data entries here
    var dataEntries: [BarChartDataEntry] = []
    var dataEntries1: [BarChartDataEntry] = []
    
    for i in 0..<xAxisData.count {
        let dataEntry = BarChartDataEntry(x: Double(i) , y: yAxisData1[i])
        dataEntries.append(dataEntry)
        
        let dataEntry1 = BarChartDataEntry(x: Double(i) , y: yAxisData2[i])
        dataEntries1.append(dataEntry1)
    }
    
    let noZeroFormatter = NumberFormatter()
    noZeroFormatter.zeroSymbol = ""
    noZeroFormatter.numberStyle = .decimal

    let chartDataSet = BarChartDataSet(values: dataEntries, label: label1)
    chartDataSet.valueFormatter = DefaultValueFormatter(formatter: noZeroFormatter)

    let chartDataSet1 = BarChartDataSet(values: dataEntries1, label: label2)
    chartDataSet1.valueFormatter = DefaultValueFormatter(formatter: noZeroFormatter)

    let dataSets: [BarChartDataSet] = [chartDataSet, chartDataSet1]
    chartDataSet.colors = [colorChart1]
    chartDataSet1.colors = [colorChart2]
    
    let chartData = BarChartData(dataSets: dataSets)
    let groupSpace = 0.4
    let barSpace = 0.03
    let barWidth = 0.2
    
    chartData.barWidth = barWidth;
    chartData.groupBars(fromX: 0.0, groupSpace: groupSpace, barSpace: barSpace)
    barChartView.data = chartData
    barChartView.xAxis.granularity = 0.5
    barChartView.notifyDataSetChanged()
    //barChartView.setVisible  //setVisibleXRangeMaximum(14)
    //chart animation
    barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .linear)

Charts Environment

Charts version/Branch/Commit Number: Latest version
Xcode version:10.1
Swift version:4
Platform(s) running Charts:
macOS version running Xcode:10.14.2

screenshot 2019-02-14 at 4 26 09 pm
screenshot 2019-02-14 at 4 29 11 pm

@drewster99
Copy link

try this:

barChartView.xAxis.granularity = 1
barChartView.xAxis.labelCount = 12

@jiffy-arti
Copy link
Author

Resolved thanks a lot...

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