We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

text display in graph

I am using syncfusion version 5.2. In my column graph i want that the text should be displayed inside the column and at the top of the column.

I am able to display text at only one point either inside or at top....but i want to display text at both points.

Image of what exactly i want is also attached with this message.

I will be very thankful if anyone could help me with this.





help_13af498f.zip

1 Reply

MA Manohari Syncfusion Team June 30, 2008 04:40 AM UTC

Hi Prabhjeet,

Thanks for the screenshot. It is possible to display text both inside as well as in the top of the column by handling the ChartAreaPaintEvent Handler as given below:

Sample Code:

void chartControl1_ChartAreaPaint(object sender, PaintEventArgs e)
{

if (this.checkBox1.Checked)
{
float y2 = this.chartControl1.PrimaryYAxis.GetCoordinateFromValue(this.chartControl1.PrimaryYAxis.Range.Min);

for (int i = 0; i < this.chartControl1.Series[0].Points.Count; i++)
{
ChartStyleInfo style = this.chartControl1.Series[0].Styles[i];
string s = String.Format("{0:n0}", this.chartControl1.Series[0].Points[i].YValues[0] / this.totalYValue * 100).ToString() + "%";
SizeF sz = e.Graphics.MeasureString(s, style.GdipFont);
float StartX = this.chartControl1.PrimaryXAxis.GetCoordinateFromValue(this.chartControl1.Series[0].Points[i].X) - sz.Width / 2;
float StartY = this.chartControl1.PrimaryYAxis.GetCoordinateFromValue(this.chartControl1.Series[0].Points[i].YValues[0]);
float MiddleY = y2 - StartY;
e.Graphics.DrawString(s, style.GdipFont, new SolidBrush(Color.Black), new PointF(StartX, StartY + (MiddleY / 2) - sz.Height / 2));

}
}

I have attached sample that illustrates the same in this link below.

http://websamples.syncfusion.com/samples/Chart.Windows/F74729/Main.htm

Kindly let us know if this meets your requirements. Thanks for your patience.

Regards,
Manohari.R



Loader.
Live Chat Icon For mobile
Up arrow icon