-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Center text vertically #682
Comments
could you specify which font size are you using, also is it axis label text or value text? A screenshot is even better. |
In case there is a single value, I use the chartView.noDataText field to display it, using font size 36 (with chartView.data == nil). |
a single value, but using no data text? Confused. Can you post a screenshot? |
You may try this code, to display the "single" value converted into a string that will sit in the middle of the "chart": UIFontDescriptor* bodyDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; PieChartView* chartView = [[PieChartView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)]; chartView.infoTextColor = [UIColor redColor]; chartView.noDataText = @"99%"; // the "single" value is converted into text here // Remove the chart legend + label "description" |
OK I checked the code: public class func drawText(context context: CGContext, text: String, var point: CGPoint, align: NSTextAlignment, attributes: [String : AnyObject]?)
{
if (align == .Center)
{
point.x -= text.sizeWithAttributes(attributes).width / 2.0
} It seems it just tried to center x but no y. I will file a PR later. |
…raw it in center
I think I've got a better way to fix it: In ChartViewBase.drawRect(rect), use lineHeight to center vertically before calling ChartUtils.drawText() CGContextSaveGState(context) I noticed the same in PieChartRenderer.drawValues(context) // y -= lineHeight |
You could file a PR for this. Mine is closed since I don't see the big picture and don't have much time for details right now. Hope you can fix them all from my PR. There are two texts for no data case. We need adjust them all. |
Modifying drawText is the wrong approach and will make all text drawing in axises incorrect. |
When using big fonts, I noticed that text is not actually vertically centered.
Adding this in DrawUtils.drawText() makes it work:
if let font = attributes?[NSFontAttributeName] as? UIFont {
point.y -= font.lineHeight / 2
}
The text was updated successfully, but these errors were encountered: