You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Charts 3.1.1 and I can't figure out how to make the chart display x-Axis gridlines when there is only one data point to display:
In this example, I want the chart to display the xAxis gridlines and labels after Apr 25, which would be Apr 26, Apr 27, Apr28, Apr 29, Apr 30, May 1 because I've set my min and max like this:
The date(s) on the x-Axis come from a property of each ChartDataEntry. XAxisRenderer uses xAxis.entries to generated the gridlines in its renderGridlines(context:) method. So, in my example of just one datapoint, that means there's just one entry so I get the single xAxis gridline.
I created this class to generate enough dates to fill in the blanks when there isn't a datapoint for each subsequent day that I want to show:
class AxisValuesGenerator: NSObject {
var days: [String]? = []
func generatexAxisDates(liftEvents: [LiftEvent]) -> [String]? {
var dates: [Date] = []
let intervalBetweenDates: TimeInterval = 3600 * 24 // 3600 = 1 hour
let firstDate = (liftEvents.first?.date)! // - intervalBetweenDates
var lastDate = liftEvents.last?.date
if Double(liftEvents.count) < 7 {
let daysToAdd = intervalBetweenDates * Double(7 - liftEvents.count)
lastDate = lastDate?.addingTimeInterval(daysToAdd)
for _ in 0...6 {
dates = self.intervalDates(from: firstDate, to: lastDate!, with: intervalBetweenDates)
}
} else {
dates = self.intervalDates(from: firstDate, to: lastDate!, with: intervalBetweenDates)
}
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM d"
days = dates.map {dateFormatter.string(from: $0)}
return days
}
func intervalDates(from startDate: Date, to endDate:Date, with interval:TimeInterval) -> [Date] {
guard interval > 0 else { return [] }
var dates:[Date] = [startDate]
var currentDate = startDate
while currentDate <= endDate {
currentDate = currentDate.addingTimeInterval(interval)
dates.append(currentDate)
}
return dates
}
I'm using Charts 3.1.1 and I can't figure out how to make the chart display x-Axis gridlines when there is only one data point to display:
In this example, I want the chart to display the xAxis gridlines and labels after Apr 25, which would be Apr 26, Apr 27, Apr28, Apr 29, Apr 30, May 1 because I've set my min and max like this:
chartView.setVisibleXRange(minXRange: 7.0, maxXRange: 7.0)
The date(s) on the x-Axis come from a property of each
ChartDataEntry
.XAxisRenderer
usesxAxis.entries
to generated the gridlines in itsrenderGridlines(context:)
method. So, in my example of just one datapoint, that means there's just one entry so I get the single xAxis gridline.I created this class to generate enough dates to fill in the blanks when there isn't a datapoint for each subsequent day that I want to show:
and it does generate the dates I want:
but the chart won't display them or their gridlines.
How can I get those vertical x-Axis gridlines to appear?
The text was updated successfully, but these errors were encountered: