Convert Bar Chart to a Grouped Bar Chart with Danielgindi/Ios-Charts and Swift

Convert bar chart to a grouped bar chart with danielgindi/ios-charts and Swift

You haven't actually done anything with unitsBought.

For a bar chart you can do two things:

  1. Add another DataSet with your unitsBought
  2. Use the other overload of BarCharDataEntry(values: [Double], xIndex: Int) or BarCharDataEntry(values: [Double], xIndex: Int, label: String) to pass multiple values per entry, which makes it stacked.

How to switch from Grouped Bar chart to Simple Bar Charts

I found the answer on the Documentation. It was quite hard to find.
The only thing u have to do is call the fitScreen() method And its gets to the original state.

func updateBarchart(which segment: Int)
{

//getSumofMonths()

let pecsColor = UIColor(red:0.278, green:0.247, blue:0.247, alpha: 1.000)
let petreColor = UIColor(red:0.941, green:0.400, blue:0.184, alpha: 1.000)

if segment == 1
{
let dataSets = [createDataSet(from: pecsBevetel, label: "Pécs", color: pecsColor),createDataSet(from: petreBevetel, label: "Újpetre", color: petreColor)]

groupedBarChart.setGroupedBarchartData(from: dataSets, xValues: monthStrings)
groupedBarChart.xAxis.granularityEnabled = true
groupedBarChart.xAxis.granularity = groupedBarChart.xAxis.axisMaximum / Double(monthStrings.count)

groupedBarChart.xAxis.axisMaximum = Double(12)
groupedBarChart.setVisibleXRangeMaximum(6)
//groupedBarChart.setVisibleXRangeMinimum(0)
groupedBarChart.xAxis.centerAxisLabelsEnabled = true

}
else if segment == 0
{
groupedBarChart.setBarChartData(xValues: monthStrings, yValues: pecsBevetel, label: "Pécs", colors: [pecsColor])
//groupedBarChart.setVisibleXRangeMinimum(12)
groupedBarChart.xAxis.centerAxisLabelsEnabled = false
groupedBarChart.fitScreen() //<- This method solves the problem.




}
else if segment == 2
{
groupedBarChart.setBarChartData(xValues: monthStrings, yValues: petreBevetel, label: "Újpetre", colors: [petreColor])
//groupedBarChart.setVisibleXRangeMinimum(12)
groupedBarChart.xAxis.centerAxisLabelsEnabled = false
groupedBarChart.fitScreen() //<- This method solves the problem.

}

//groupedBarChart.xAxis.axisMinimum = Double(0.5)
groupedBarChart.xAxis.labelPosition = XAxis.LabelPosition.bottom
groupedBarChart.chartDescription?.text = ""

groupedBarChart.fitBars = true


groupedBarChart.doubleTapToZoomEnabled = false


let legend = groupedBarChart.legend
legend.enabled = true
legend.horizontalAlignment = .center
legend.verticalAlignment = .bottom
legend.orientation = .horizontal
legend.drawInside = false
legend.yEntrySpace = 0.0;

let marker = BalloonMarker(color: UIColor.white, font: UIFont.systemFont(ofSize: 12), textColor: UIColor.black, insets: UIEdgeInsetsMake(8.0, 8.0, 20.0, 8.0))
marker.minimumSize = CGSize(width: 75.0, height: 35.0)
groupedBarChart.marker = marker
groupedBarChart.drawMarkers = true
groupedBarChart.moveViewToX(0)

}

So to be short call this method AFTER you set the data of the chart.

groupedBarChart.fitScreen() //<- This method solves the problem.

iOS Charts remove values on the bar of the bar chart

Add following line of code where you setup sets of chart to fix your issue:

var set = BarChartDataSet(values: yVals, label: "Data Set")        
set.drawValuesEnabled = false // Set this property to false to hide all values

let data = BarChartData(dataSet: set)
yourChartView.data = data

This code will hide all values above bar chart. I hope this will help you.



Related Topics



Leave a reply



Submit