tags:

views:

32

answers:

1

Hi, I use PostPaint event of Chart control to embellish my chart. Along with other stuff I draw custom labels. For drawing text I use the same font as axes has, the default one:

Graphics g = e.ChartGraphics.Graphics;  
SizeF textSize = g.MeasureString(label, chart.ChartAreas[0].AxisX.LabelStyle.Font);  
g.DrawString(label, chart.ChartAreas[0].AxisX.LabelStyle.Font, System.Drawing.Brushes.Black, 
    new RectangleF(new PointF(location.X - textSize.Width / 2, location.Y), textSize), LabelFormat);   

However the produced text in the result chart is horrible (labels 100 and 200):

Screenshot

How can I make the custom text look as the original?

A: 

For starters, you can try to align your text rendering on whole pixels (if it's not already the case, I'm not sure of the types you're using in your example). For a quick test, just cast your new PointF() parameters to int :

/*...*/ new PointF((int)(location.X - textSize.Width / 2), (int)location.Y)
jv42