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

Creating Stacked Bar Chart How To Round Corner Radius Of Bar and How To Set DataPoints Background Color #5170

Open
AGL-Pulkit-AGL opened this issue Apr 29, 2024 · 0 comments

Comments

@AGL-Pulkit-AGL
Copy link

func setChartBarGroupDataSet(dataPoints: [String], values1: [Double], values2: [Double],values3: [Double],values4: [Double],values5: [Double]) {

    var dataEntries1: [BarChartDataEntry] = []
    var dataEntries2: [BarChartDataEntry] = []
    var dataEntries3: [BarChartDataEntry] = []
    var dataEntries4: [BarChartDataEntry] = []
    var dataEntries5: [BarChartDataEntry] = []
    
    for i in 0..<dataPoints.count {
        
        let dataEntry1 = BarChartDataEntry(x: Double(i) , y: values1[i])
        dataEntries1.append(dataEntry1)
        
        let dataEntry2 = BarChartDataEntry(x: Double(i) , y: values2[i])
        dataEntries2.append(dataEntry2)
        
        let dataEntry3 = BarChartDataEntry(x: Double(i) , y:values3[i])
        dataEntries3.append(dataEntry3)
        
        let dataEntry4 = BarChartDataEntry(x: Double(i) , y:values4[i])
        dataEntries4.append(dataEntry4)
        
        let dataEntry5 = BarChartDataEntry(x: Double(i) , y:values5[i])
        dataEntries5.append(dataEntry5)
    }
    
    let chartDataSet1 = BarChartDataSet(entries: dataEntries1, label: "Google")
    let chartDataSet2 = BarChartDataSet(entries: dataEntries2, label: "FaceBook")
    let chartDataSet3 = BarChartDataSet(entries: dataEntries3, label: "Emailer")
    let chartDataSet4 = BarChartDataSet(entries: dataEntries4, label: "LinkedIn")
    let chartDataSet5 = BarChartDataSet(entries: dataEntries5, label: "Website")
    
    
   
    
    // Mark Show Minimum Number Of Bar Graph and Scroll Start
    let visibleXRange = 5 // Number of values to show in y-Axis
    barChartView.xAxis.axisMaximum = Double(dataEntries1.count)
    barChartView.setVisibleXRangeMaximum(Double(visibleXRange))
    barChartView.xAxis.setLabelCount(visibleXRange, force: true)
    barChartView.xAxis.labelCount = visibleXRange
    barChartView.dragEnabled = true
    // Mark Show Minimum Number Of Bar Graph and Scroll End
    
    // Mark Show and Remove Values Show In Bar Start
    chartDataSet1.drawValuesEnabled = true
    chartDataSet2.drawValuesEnabled = false
    chartDataSet3.drawValuesEnabled = false
    chartDataSet4.drawValuesEnabled = false
    chartDataSet5.drawValuesEnabled = false
    
    
    // Mark Remove Values Show In Bar End
    
    chartDataSet1.colors =  [UIColor(red: 118/255, green: 153/255, blue: 31/255, alpha: 1)]
    chartDataSet2.colors =  [UIColor(red: 0/255, green: 163/255, blue: 217/255, alpha: 1)]
    chartDataSet3.colors =  [UIColor(red: 229/255, green: 175/255, blue: 23/255, alpha: 1)]
    chartDataSet4.colors =  [UIColor(red: 54/255, green: 87/255, blue: 178/255, alpha: 1)]
    chartDataSet5.colors =  [UIColor(red: 229/255, green: 55/255, blue: 34/255, alpha: 1)]
    
    
    
    
    let dataSets: [BarChartDataSet] = [chartDataSet1, chartDataSet2, chartDataSet3,chartDataSet4,chartDataSet5]
    
    let chartData = BarChartData(dataSets: dataSets)
    
    chartData.setValueFont(.systemFont(ofSize:10, weight: .semibold))
    
    
    barChartView.pinchZoomEnabled = false
    barChartView.doubleTapToZoomEnabled = false
    barChartView.drawMarkers = true
    barChartView.drawValueAboveBarEnabled = true
    barChartView.fitBars = false
    
    
    // Set Width On Barchart
    chartData.barWidth = 0.8;
    
    
    
    // Set space between groups of bars
    
    barChartView.data = chartData
    
    // Set the marker for the chart view
    
    
    // barChartView.chartDescription.text = "Laxmi Mittal Production Data"
    // barChartView.chartDescription.textColor = #colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 1)
    
    barChartView.animate(xAxisDuration: 1.5, yAxisDuration: 1.5, easingOption: .easeInBounce)
    barChartView.notifyDataSetChanged()
    
}
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