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

not able to display x-axis labels like (jun, july) in line chart #3509

Closed
Nallamsetty opened this issue Jun 13, 2018 · 1 comment
Closed

Comments

@Nallamsetty
Copy link

here is the code, please help me...

fileprivate func setLineChart(_ lineChartView: LineChartView, dataPoints: [String], values: [Double]) {

        // 1 - creating an array of data entries
        var dataEntries: [ChartDataEntry] = []
        for i in 0..<values.count {
            let dataEntry = ChartDataEntry(x: Double(i), y: values[i])
            dataEntries.append(dataEntry)
        }
        
        // 2 - create a data set with our array
        let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "LINE CHART")
        lineChartDataSet.setColor(UIColor.blue)
        // lineChartDataSet.drawCubicEnabled = true
        lineChartDataSet.mode = .cubicBezier
        lineChartDataSet.drawCirclesEnabled = true
        lineChartDataSet.lineWidth = 1.0
        lineChartDataSet.circleRadius = 5.0
        
        
        lineChartDataSet.drawFilledEnabled = true
        lineChartDataSet.fillColor = .green
        
        // lineChartDataSet.fillAlpha = 65 / 225.0
        lineChartDataSet.highlightColor = UIColor.orange
        lineChartDataSet.setCircleColor(UIColor.blue)
        // lineChartDataSet.circleColors = [UIColor.red]
        // lineChartDataSet.label = ""
        lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = true
        
        //3 - create an array to store our LineChartDataSets
        var dataSets = [IChartDataSet]()
        dataSets.append(lineChartDataSet)
        
        //4 - pass our months in for our x-axis label value along with our dataSets
        let lineChartData = LineChartData(dataSets: dataSets)
        lineChartData.setValueTextColor(UIColor.black)
        
        // x-axis
        lineChartView.xAxis.labelPosition = .bottom
        lineChartView.xAxis.drawGridLinesEnabled = true
        lineChartView.xAxis.granularity = 1.0
        lineChartView.xAxis.setLabelCount(dataPoints.count, force: true)
        lineChartView.gridBackgroundColor = UIColor.red
        lineChartView.data = lineChartData
        
    }
@Nallamsetty Nallamsetty changed the title not able to get x-axis labels in line chart not able to display x-axis labels like (jun, july) in line chart Jun 13, 2018
@liuxuan30
Copy link
Member

ask on stack overflow.

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