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

3.0.5 Bar chart xAxis valueFormatter regression - no data points shown. #3233

Closed
rl-pavel opened this issue Feb 1, 2018 · 7 comments
Closed

Comments

@rl-pavel
Copy link

rl-pavel commented Feb 1, 2018

I've recently updated my dependencies and noticed that the data points on my bar chart's X axis are gone. After some digging, this seems like a regression since 3.0.4.

The reason I think it's due to valueFormatting is because if I comment out this line:

barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: chartData.dataPoints)

the indexes of each bar are still showing.

Here are a few screenshots:

iphone 8 - 11 2 2018-02-01 16-17-08

iphone 8 - 11 2 2018-02-01 16-09-57

iphone 8 - 11 2 2018-02-01 15-50-57


Here's my chart configuration, in case it affects anything:

barChart.delegate = self

// Left axis configurations
barChart.leftAxis.drawAxisLineEnabled = false
barChart.leftAxis.setLabelCount(4, force: true)
barChart.leftAxis.labelFont = UNFont.font(with: UNFontSize11, type: UNFontTypeRegular)
barChart.leftAxis.labelTextColor = UNColor.whiteColor().withAlphaComponent(0.5)
barChart.leftAxis.gridColor = UNColor.blueLightColor()
barChart.leftAxis.axisMinimum = 0
barChart.leftAxis.valueFormatter = UNYAxisValueFormatter()

// Right axis configurations
barChart.rightAxis.drawAxisLineEnabled = false
barChart.rightAxis.drawGridLinesEnabled = false
barChart.rightAxis.drawLabelsEnabled = false

// X axis configurations
barChart.xAxis.granularityEnabled = true
barChart.xAxis.granularity = 1
barChart.xAxis.drawAxisLineEnabled = false
barChart.xAxis.drawGridLinesEnabled = false
barChart.xAxis.labelFont = UNFont.font(with: UNFontSize11, type: UNFontTypeRegular)
barChart.xAxis.labelTextColor = UNColor.whiteColor().withAlphaComponent(0.5)
barChart.xAxis.labelPosition = .bottom

// Other configurations
barChart.highlightPerDragEnabled = false
barChart.chartDescription?.text = ""
barChart.legend.enabled = false
barChart.pinchZoomEnabled = false
barChart.doubleTapToZoomEnabled = false
barChart.scaleYEnabled = false

// Marker configuration
_tooltipView.chartView = barChart
barChart.marker = _tooltipView
// Initially false to highlight the last value without showing the marker
barChart.drawMarkers = false

barChart.snp.make(.all, .equalToSuperview)
backgroundColor = .clear

And here's how I configure the data:

// Prevent from setting an empty data set to the chart (crashes)
guard chartData.dataPoints.count > 0 else { return }

var dataEntries = [BarChartDataEntry]()

for i in 0..<chartData.dataPoints.count {
	let entry = BarChartDataEntry(x: Double(i), y: chartData.dataValues[i])
	dataEntries.append(entry)
}

let barChartData = BarChartData()

let barChartDataSet = BarChartDataSet(values: dataEntries, label: "")
barChartDataSet.drawValuesEnabled = false
barChartDataSet.colors = [UNColor.blueLightColor()]
barChartDataSet.highlightColor = UNColor.whiteColor()
barChartDataSet.highlightAlpha = 1

barChartData.addDataSet(barChartDataSet)
barChartData.barWidth = 0.7

barChartView.barChart.data = barChartData
barChartView.barChart.setVisibleXRange(minXRange: 5, maxXRange: 5.5)
barChartView.barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: chartData.dataPoints)

// If user didn't change highlight, then highlight last bar
if !barChartView.didChangeHighlight {
	barChartView.barChart.moveViewToX(Double(chartData.dataPoints.count))
	barChartView.barChart.highlightValue(x: Double(chartData.dataPoints.count), dataSetIndex: 0, stackIndex: 0)
	
} else if let highlightIndex = barChartView.highlightIndex {
	barChartView.barChart.moveViewToX(highlightIndex)
}

note: chartData is a tuple: (dataPoints: [String], dataValues: [Double])

@rl-pavel rl-pavel changed the title 3.0.5 Bar chart xAxis valueFormatter regression - no data points. 3.0.5 Bar chart xAxis valueFormatter regression - no data points shown. Feb 1, 2018
@rl-pavel
Copy link
Author

rl-pavel commented Feb 1, 2018

Closing because #3174 seems to have fixed this.

@rl-pavel rl-pavel closed this as completed Feb 1, 2018
@mikeCalvir
Copy link

I just down-versioned to 3.0.4 but my xAxis labels still never show. If I break on my value converter it is called and returns a correct string, but I've never seen an x axis label so far (just started using this framework).

My config:

    ChartXAxis *xAxis = self.chartView.xAxis;
    xAxis.labelPosition = XAxisLabelPositionBottom;
    xAxis.labelFont = [UIFont defaultOfSize:12.f];
    xAxis.labelTextColor = UIColor.blackColor;
    xAxis.drawGridLinesEnabled = NO;
    xAxis.drawAxisLineEnabled = YES;
    xAxis.wordWrapEnabled = YES;
    xAxis.granularity = 1;
    xAxis.granularityEnabled = YES;
    xAxis.valueFormatter = [[DateValueFormatter alloc] init];

@rl-pavel
Copy link
Author

rl-pavel commented Feb 1, 2018

@mikeCalvir You have to provide the values to the formatter. There's an initialized that accepts and array of strings, try using that.

@mikeCalvir
Copy link

Thanks for the reply and the suggestion @Pahitos.
But, I'm using a Scatter chart and I want the user to be able to zoom in (from a week down to say an hour or few).
I have loaded all the data X positions with timeinterval values, and they are being passed to my DateValueFormatter instance and it is returning correct strings.
But still nothing.

If I initialize it with an array of strings, given I have hundreds of points, I don't see how it will work correctly?

Thanks for any help, hopefully I'm being slow and missing something obvious, it would be great to see any x labels at all at this point :)

@mikeCalvir
Copy link

Also even if I don't specify any formatter, I was expecting to see just the timeinterval numbers, but I get nothing.

@rl-pavel
Copy link
Author

rl-pavel commented Feb 1, 2018

I've never used a scatter chart unfortunately. Can you send a screenshot of what you're seeing?

@mikeCalvir
Copy link

mikeCalvir commented Feb 1, 2018 via email

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