We are updating our code to work with DGCharts v.4.0 (previously Charts) and our previously working solution (see below) for adding titles for the x and y axis is now no longer working, as "ChartUtils" cannot be found.
Does anyone know how this can be achieved with DGCharts?
`// MARK: Y-Axis titles.
private extension LineChartYAxisRenderer {
func renderTitle(title: String, inContext context: CGContext, x: CGFloat) {
var foregroundColor = UIColor.darkGray
if #available(iOS 13.0, *) {
foregroundColor = UIColor.secondaryLabel
}
let attributes: [NSAttributedString.Key: Any] = [
.font: self.axis.labelFont,
.foregroundColor: foregroundColor
]
// Determine the chart title's y-position.
let titleSize = title.size(withAttributes: attributes)
let verticalTitleSize = CGSize(width: titleSize.height, height: titleSize.width)
let point = CGPoint(x: x, y: ((viewPortHandler.chartHeight - verticalTitleSize.height) / 2)-30)
// Render the chart title.
ChartUtils.drawText(context: context,
text: title,
point: point,
attributes: attributes,
anchor: .zero,
angleRadians: .pi / -2)
}
}`
