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

How to access the Position of labels on x axis of Combined Line and Bar chart on swift(3.0.1) #2131

Closed
goel232 opened this issue Feb 2, 2017 · 1 comment

Comments

@goel232
Copy link

goel232 commented Feb 2, 2017

I have done the same thing in swift2 like this

       func setChart(_ xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double] ,         combinedChartView:CombinedChartView) {        
          
      combinedChartView.noDataText = "Please provide data for the chart."
          var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
          var yVals2 : [BarChartDataEntry] = [BarChartDataEntry]()  
      for i in 0..<xValues.count {
            
          yVals1.append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
          yVals2.append(BarChartDataEntry(value: yValuesBarChart[i] , xIndex: i))
            
        }
    let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
    let barChartSet: BarChartDataSet = BarChartDataSet(yVals: yVals2, label: "Bar Data")

    let data: CombinedChartData = CombinedChartData(xVals: xValues)
    data.barData = BarChartData(xVals: xValues, dataSets: [barChartSet])
    if yValuesLineChart.contains(0) == false {
    data.lineData = LineChartData(xVals: xValues, dataSets: [lineChartSet])
    }
    combinedChartView.data = data
}

screen shot 2017-02-02 at 10 44 58 am

@goel232 goel232 changed the title How to access the labels on x axis of Combined Line and Bar chart on swift(3.0.1) How to access the Position of labels on x axis of Combined Line and Bar chart on swift(3.0.1) Feb 2, 2017
@goel232
Copy link
Author

goel232 commented Feb 2, 2017

found the answer

     func setChart(_ xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double] , combinedChartView:CombinedChartView) {
        combinedChartView.noDataText = "Please provide data for the chart."
    
    var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
    var yVals2 : [BarChartDataEntry] = [BarChartDataEntry]()
    for i in 0..<xValues.count {
        yVals1.append(ChartDataEntry(x: Double(i), y: yValuesLineChart[i],data: xValues as AnyObject?))
        yVals2.append(BarChartDataEntry(x: Double(i), y: yValuesBarChart[i],data: xValues as AnyObject?))
    }
        let lineChartSet = LineChartDataSet(values: yVals1, label: "Line Data")
        let barChartSet: BarChartDataSet = BarChartDataSet(values: yVals2, label: "Bar Data")
        let data: CombinedChartData = CombinedChartData()
        data.barData=BarChartData(dataSets: [barChartSet])
        if yValuesLineChart.contains(0) == false {
            data.lineData = LineChartData(dataSets:[lineChartSet] )
            
        }
        **combinedChartView.data = data
        combinedChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:xValues)
        combinedChartView.xAxis.granularity = 1**
        }

@goel232 goel232 closed this as completed Feb 2, 2017
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

1 participant