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

fitBars doesnt seems to work #2088

Closed
iosBeappTeam opened this issue Jan 17, 2017 · 4 comments
Closed

fitBars doesnt seems to work #2088

iosBeappTeam opened this issue Jan 17, 2017 · 4 comments

Comments

@iosBeappTeam
Copy link

Hello, i m trying to display 24 bar and grouped 2 by 2.
So if i understand correctly the fitbar property my bar should resize for showing the 24 bars considering the frame of the chart ?
img_0799

Sorry for the dirty code.
`barChart.descriptionText = ""

	barChart.leftAxis.axisMinValue = 0.0
	barChart.leftAxis.axisMaxValue = 1000.0
	
	barChart.xAxis.axisMaximum = 12
	barChart.xAxis.axisMinimum = 0
	barChart.xAxis.wordWrapEnabled = true
	barChart.xAxis.drawGridLinesEnabled = true
	barChart.xAxis.labelPosition = .bottom
	barChart.xAxis.forceLabelsEnabled = false
	barChart.xAxis.centerAxisLabelsEnabled = false
	barChart.xAxis.valueFormatter =  xValueFormatter()
	//	barChart.xAxis.spaceMin = 0.5
	//barChart.xAxis.spaceMax = 0.5
	//barChart.xAxis.setLabelCount(12, force: false)
	//barChart
	//		barChart.xAxis.labelWidth = 80
	
	barChart.rightAxis.enabled = false
	barChart.legend.enabled = true
	barChart.scaleYEnabled = false
	barChart.scaleXEnabled = false
	barChart.pinchZoomEnabled = true
	barChart.drawValueAboveBarEnabled = true
	barChart.doubleTapToZoomEnabled = false
	
	// Get and prepare the data
	let sales = ChartDataGenerator.data()
	let sales2 = ChartDataGenerator.data2()
	
	// Initialize an array to store chart data entries (values; y axis)
	var salesEntries = [ChartDataEntry]()
	var salesEntries2 = [ChartDataEntry]()
	
	// Initialize an array to store months (labels; x axis)
	var salesMonths = [String]()
	
	var i = 0
	for sale in sales {
		// Create single chart data entry and append it to the array
		//let saleEntry = BarChartDataEntry(value: sale.value, xIndex: i)
		let saleEntry = BarChartDataEntry(x: Double(i), yValues: [sale.value], label: sale.month)
		salesEntries.append(saleEntry)
		let saleEntry2 = BarChartDataEntry(x: Double(i), yValues: [sales2[i].value], label: sales2[i].month)
		salesEntries2.append(saleEntry2)

		print(i)
		i += 1
	}
	
	
	// Create bar chart data set containing salesEntries
	let chartDataSet = BarChartDataSet(values: salesEntries, label: "Profit 1 ")
	let chartDataSet2 = BarChartDataSet(values: salesEntries2, label: "N -1")
	chartDataSet.colors = [NSUIColor(red: 53/255.0, green: 194/255.0, blue: 209/255.0, alpha: 1.0)]
	chartDataSet2.colors = [NSUIColor(red: 73/255.0, green: 214/255.0, blue: 239/255.0, alpha: 1.0)]

	// Create bar chart data with data set and array with values for x axis
	//let chartData = BarChartData(xVals: salesMonths, dataSets: [])
	let chartData = BarChartData(dataSets: [chartDataSet, chartDataSet2])
	chartData.groupBars(fromX: 0.001, groupSpace: 0.3, barSpace: 0.1)
	
	// Set bar chart data to previously created data
	barChart.data = chartData
	//barChart.xAxisRenderer.computeAxisValues(min: 0, max: 12)
	barChart.fitBars = true

	
	// Animation
	barChart.animate(yAxisDuration: 1.5, easingOption: .easeInOutQuart)`
@liuxuan30
Copy link
Member

liuxuan30 commented Jan 18, 2017

I don't understand. fitBars just display the missing part of the bar chart:

/// Adds half of the bar width to each side of the x-axis range in order to allow the bars of the barchart to be fully displayed.
/// default: false
open var fitBars = false

take MultipleBarChartViewController in ChartsDemo to refer.

@iosBeappTeam
Copy link
Author

So there is nothing to force the graph to adapt his display to the frame ?
I mean, as you can see in the screen that's not displaying 24 bar, but i need to display it, how can i do that ?

@iosBeappTeam
Copy link
Author

I v found the problem i m explaining you.
The problem is that, when we are in grouped bar, the x value of each bar become overrided, but thats not doing any relation to the x value normally needed for the bar.

As you can see on this graph the selected bar is normaly in march if i dont set them in "group"
img_0795

@liuxuan30
Copy link
Member

sorry take a long break. It seems you just misused it. Have you looked at ChartsDemo? It works fine

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